From 369ecd14db45c9eacfc43f06ae71503f9f338a40 Mon Sep 17 00:00:00 2001 From: Austen Adler Date: Tue, 3 Jan 2017 16:47:04 +0000 Subject: [PATCH] Added main code --- .gitignore | 1 + main.c | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+) create mode 100644 main.c diff --git a/.gitignore b/.gitignore index 5ac559f..da9353d 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ flush new prompt sr +main diff --git a/main.c b/main.c new file mode 100644 index 0000000..0163fd5 --- /dev/null +++ b/main.c @@ -0,0 +1,78 @@ +#include +#include +#include +#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 +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; + updateColors(); + delay(1000); +} +void changeAllColors(bool red, bool green, bool blue) { + colorField[0] = red; + colorField[1] = green; + colorField[2] = blue; + colorField[3] = red; + colorField[4] = green; + colorField[5] = blue; +} +int main(void) { + wiringPiSetup(); + pinMode(DATA_PIN, OUTPUT); + pinMode(CLOCK_PIN, OUTPUT); + pinMode(LATCH_PIN, OUTPUT); + changeAllColors(OFF); + updateColors(); + delay(1000); + for(;;) { + changeColor(LEFT, RED); + changeColor(LEFT, OFF); + changeColor(LEFT, GREEN); + changeColor(LEFT, OFF); + changeColor(LEFT, BLUE); + changeColor(LEFT, OFF); + changeColor(LEFT, PURPLE); + changeColor(LEFT, OFF); + } +}