Skip to content

Instantly share code, notes, and snippets.

@chris-gunawardena
Created September 1, 2016 12:18
Show Gist options
  • Save chris-gunawardena/45129959e3721548d28e10c67ec49de7 to your computer and use it in GitHub Desktop.
Save chris-gunawardena/45129959e3721548d28e10c67ec49de7 to your computer and use it in GitHub Desktop.
// +-\/-+
// (+) VCC 1| |14 GND (-)
// coil 1 A00 2| |13 A10 low_pin
// coil 2 A01 3| |12 A09 high_pin
// RESET 4| |11 A08
// coil 3 A02 5| |10 A07 button_input
// A03 6| |9 A06 led_cathode
// A04 7| |8 A05 led_anode
// +----+
int low_pin = 10;
int high_pin = 9;
int button_input = 7;
int led_anode = 5;
int led_cathode = 6;
void setup() {
pinMode(0, OUTPUT); pinMode(1, OUTPUT); pinMode(2, OUTPUT);
// used for led
pinMode(led_anode, OUTPUT); digitalWrite(led_anode, LOW);
pinMode(led_cathode, OUTPUT); digitalWrite(led_cathode, LOW);
// button
pinMode(button_input, INPUT);
pinMode(low_pin, OUTPUT); digitalWrite(low_pin, LOW);
pinMode(high_pin, OUTPUT); digitalWrite(high_pin, HIGH);
}
int on_time = 25; //in ms
int refresh_rate = 1; // per second
int pins = 3;
int off_time = (1000 / (refresh_rate * (pins + 1))) - on_time; //in ms (1: 225/25 2:100/25)
void loop() {
for (int pin = 0; pin <= pins; pin++) {
digitalWrite(pin, HIGH);
delay(on_time);
digitalWrite(pin, LOW);
delay(off_time);
}
if (digitalRead(button_input) == HIGH) {
on_time = on_time + 5;
off_time = (1000 / (refresh_rate * (pins + 1))) - on_time; //in ms
int blink_num = on_time / 5;
for (int i = 0; i < blink_num; i++) {
digitalWrite(led_anode, HIGH); // turn the LED on (HIGH is the voltage level)
delay(50); // wait for a second
digitalWrite(led_anode, LOW); // turn the LED off by making the voltage LOW
delay(200);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment