Last active
August 9, 2016 22:27
-
-
Save NoraCodes/aebf07d6f8ae6fec27235223ee149aa5 to your computer and use it in GitHub Desktop.
Blinky Grid wired programmer sketch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Data and clock lines for the BlinkyGrid | |
| #define BG_CLOCK 2 | |
| #define BG_DATA 8 | |
| // How long to take for each half cycle | |
| #define CL_DELAY 50 | |
| // Keep track of the current state of the clock | |
| bool c = false; | |
| // Keep track of the position in the data | |
| int i = 0; | |
| // The data (from xmit_raw on http://www.wayneandlayne.com/blinky_programmer/?debug) | |
| bool data[] = {0,0,0,0,0,1,0,0, // 04 | |
| 0,0,0,0,0,0,0,0, // 00 | |
| 0,0,0,0,0,0,0,0, // 00 | |
| 0,0,0,0,0,1,1,0, // 06 | |
| 0,0,0,0,0,0,0,1, // 01 | |
| 0,0,0,1,1,1,0,1, // 1D | |
| 0,0,0,0,0,0,0,1, // 01 | |
| 0,0,0,1,1,1,0,1, // 1D | |
| 1,0,1,1,1,0,1,0, // BA | |
| 0,0,0,0,0,0,0,0, // 00 | |
| 0,0,0,0,0,0,0,0, // 00 | |
| 0,0,0,0,0,0,0,0, // 00 | |
| 0,0,0,0,0,0,0,1, // 01 | |
| 1,1,1,1,1,1,1,1 // FF | |
| }; | |
| void send_bit() { | |
| // Set the data line to the desired state | |
| digitalWrite(BG_DATA, data[i]); | |
| Serial.print(data[i]); | |
| i = i + 1; | |
| } | |
| void cl() { | |
| // invert the clock state | |
| c = !c; | |
| digitalWrite(BG_CLOCK, c); | |
| // For debugging | |
| digitalWrite(13, c); | |
| } | |
| void setup() { | |
| // Pins to output | |
| pinMode(BG_CLOCK, OUTPUT); | |
| pinMode(BG_DATA, OUTPUT); | |
| pinMode(13, OUTPUT); | |
| // Set both pins low ("black" level) | |
| digitalWrite(BG_CLOCK, LOW); | |
| digitalWrite(BG_DATA, LOW); | |
| digitalWrite(13, LOW); | |
| Serial.begin(9600); | |
| Serial.println("Black level set. 5s to programming."); | |
| delay(5000); | |
| Serial.println("Programming!"); | |
| } | |
| void loop() { | |
| // Loop until the end of the data | |
| while (i < (sizeof(data))) { | |
| // Write a bit | |
| send_bit(); | |
| delay(CL_DELAY / 2); | |
| // Transit the clock | |
| cl(); | |
| delay(CL_DELAY / 2); | |
| } | |
| Serial.print("\nDone programming "); | |
| Serial.print(i); | |
| Serial.print(" bits ("); | |
| Serial.print(i / 8); | |
| Serial.print(" bytes).\n"); | |
| digitalWrite(BG_CLOCK, 0); | |
| digitalWrite(BG_DATA, 0); | |
| while (1) { | |
| delay(1000); | |
| } | |
| //i = 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment