2017-01-03 11:47:04 -05:00
|
|
|
#include <wiringPi.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdbool.h>
|
2017-01-03 11:56:12 -05:00
|
|
|
#define LATCH_PIN 2
|
|
|
|
#define CLOCK_PIN 0
|
|
|
|
#define DATA_PIN 3
|
|
|
|
#define OFF false, false, false
|
|
|
|
#define RED true, false, false
|
|
|
|
#define GREEN false, true, false
|
|
|
|
#define BLUE false, false, true
|
|
|
|
#define PURPLE true, false, true
|
2017-01-07 17:27:12 -05:00
|
|
|
#define YELLOW true, true, false
|
|
|
|
#define CYAN false, true, true
|
|
|
|
#define WHITE true, true, true
|
2017-01-03 11:47:04 -05:00
|
|
|
typedef enum { LEFT, RIGHT } Side_t;
|
|
|
|
bool colorField[] = {
|
|
|
|
false, // Left red
|
|
|
|
false, // Left green
|
|
|
|
false, // Left blue
|
|
|
|
false, // Right red
|
|
|
|
false, // Right green
|
|
|
|
false, // Right blue
|
|
|
|
false, // Unused bit
|
|
|
|
false // Unused bit
|
|
|
|
};
|
|
|
|
void write(bool mode) {
|
|
|
|
delay(10);
|
|
|
|
digitalWrite(DATA_PIN, mode);
|
|
|
|
digitalWrite(CLOCK_PIN, true);
|
|
|
|
digitalWrite(CLOCK_PIN, false);
|
|
|
|
digitalWrite(DATA_PIN, false);
|
|
|
|
}
|
|
|
|
void flushPins() {
|
|
|
|
digitalWrite(LATCH_PIN, true);
|
|
|
|
digitalWrite(LATCH_PIN, false);
|
|
|
|
}
|
|
|
|
void updateColors() {
|
|
|
|
flushPins();
|
|
|
|
for(int i = 0; i < 8; i ++){
|
|
|
|
write(colorField[i]);
|
|
|
|
}
|
|
|
|
flushPins();
|
|
|
|
}
|
|
|
|
void changeColor(Side_t side, bool red, bool green, bool blue) {
|
|
|
|
short shift = 0;
|
|
|
|
if(side == RIGHT) {
|
|
|
|
shift = 3;
|
|
|
|
}
|
|
|
|
colorField[shift] = red;
|
|
|
|
colorField[shift + 1] = green;
|
|
|
|
colorField[shift + 2] = blue;
|
|
|
|
}
|
|
|
|
void changeAllColors(bool red, bool green, bool blue) {
|
2017-01-03 11:56:12 -05:00
|
|
|
changeColor(LEFT, red, green, blue);
|
|
|
|
changeColor(RIGHT, red, green, blue);
|
2017-01-03 11:47:04 -05:00
|
|
|
}
|
|
|
|
int main(void) {
|
|
|
|
wiringPiSetup();
|
|
|
|
pinMode(DATA_PIN, OUTPUT);
|
|
|
|
pinMode(CLOCK_PIN, OUTPUT);
|
|
|
|
pinMode(LATCH_PIN, OUTPUT);
|
|
|
|
changeAllColors(OFF);
|
|
|
|
updateColors();
|
|
|
|
delay(1000);
|
2017-01-07 17:27:12 -05:00
|
|
|
int ch;
|
|
|
|
while((ch = getchar()) != EOF){
|
2017-01-07 17:37:07 -05:00
|
|
|
if (ch == 'r') {
|
2017-01-07 17:27:12 -05:00
|
|
|
changeAllColors(RED);
|
|
|
|
} else if (ch == 'g') {
|
|
|
|
changeAllColors(GREEN);
|
|
|
|
} else if (ch == 'b') {
|
|
|
|
changeAllColors(BLUE);
|
2017-01-07 17:37:07 -05:00
|
|
|
} else if(ch == 'p') {
|
|
|
|
changeAllColors(PURPLE);
|
|
|
|
} else if (ch == 'y') {
|
|
|
|
changeAllColors(YELLOW);
|
|
|
|
} else if (ch == 'c') {
|
|
|
|
changeAllColors(CYAN);
|
2017-01-07 17:27:12 -05:00
|
|
|
} else if (ch == 'o') {
|
|
|
|
changeAllColors(OFF);
|
|
|
|
} else if (ch == 'w') {
|
|
|
|
changeAllColors(WHITE);
|
|
|
|
} else {
|
|
|
|
printf("Invalid char");
|
|
|
|
continue;
|
|
|
|
}
|
2017-01-07 17:37:07 -05:00
|
|
|
updateColors();
|
2017-01-07 17:27:12 -05:00
|
|
|
delay(1000);
|
2017-01-03 11:47:04 -05:00
|
|
|
}
|
2017-01-07 17:37:07 -05:00
|
|
|
changeAllColors(OFF);
|
|
|
|
updateColors();
|
2017-01-03 11:47:04 -05:00
|
|
|
}
|
2017-01-07 17:37:07 -05:00
|
|
|
// vim: ts=2
|