Skip to content

Instantly share code, notes, and snippets.

@faebser
Created April 3, 2019 20:39
Show Gist options
  • Save faebser/fed95e4b04b5ab260d35c481699d931e to your computer and use it in GitHub Desktop.
Save faebser/fed95e4b04b5ab260d35c481699d931e to your computer and use it in GitHub Desktop.
void setup() {
// put your setup code here, to run once:
pinMode(11, OUTPUT);
pinMode(12, OUTPUT);
pinMode(A1, OUTPUT);
pinMode(A2, OUTPUT);
digitalWrite(A1, LOW);
digitalWrite(A2, LOW);
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
//light(8);
//delay(100);
//light(4);
//delay(500);
light(5);
delay(500);
light(9);
delay(500);
light(10);
delay(500);
light(6);
delay(500);
}
void light(byte input) {
Serial.print("input: ");
Serial.println(input);
for(int i = 3; i >= 0; i--) {
Serial.print(bitRead(input, i));
}
Serial.println("");
if(bitRead(input, 3) == 1) {
digitalWrite(12, HIGH);
}
else {
digitalWrite(12, LOW);
}
delay(1);
if(bitRead(input, 2) == 1) {
digitalWrite(11, HIGH);
}
else {
digitalWrite(11, LOW);
}
if(bitRead(input, 1) == 1) {
digitalWrite(A1, HIGH);
}
else {
digitalWrite(A1, LOW);
}
if(bitRead(input, 0) == 1) {
digitalWrite(A2, HIGH);
}
else {
digitalWrite(A2, LOW);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment