Created
November 5, 2017 18:52
-
-
Save benwtr/c84764e090134e428429e8bf34210bf5 to your computer and use it in GitHub Desktop.
arduino POV fan display
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
#!/usr/bin/env ruby | |
# scrappy ruby code to generate data to send over the serial connection to the transmitter | |
def figlet(str) | |
`echo #{str} | figlet -f banner3 -w 128 | cut -b1-128 | tr "#" "1" | tr " " "0"`.split("\n") | |
end | |
def reorder_for_leds(figlet_output) | |
reordered = '' | |
for i in 0..figlet_output[0].length | |
for b in 0..6 | |
begin | |
reordered += figlet_output[b][i] || '0' | |
rescue | |
reordered += '0' | |
end | |
end | |
end | |
reordered | |
end | |
@str = '' | |
@r = 254 | |
@g = 251 | |
@b = 253 | |
@delaymicros = 50 | |
def set_text(str) | |
@str = reorder_for_leds(figlet(str)) | |
end | |
def format_output | |
"#{@r} #{@g} #{@b} #{@delaymicros} #{@str}" | |
end | |
set_text ARGV.join ' ' | |
puts format_output |
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
#include <SPI.h> | |
#include <nRF24L01.h> | |
#include <RF24.h> | |
RF24 radio(A1, A0); // CE, CSN | |
const byte address[6] = "00001"; | |
const int led_pins[7] = { 2, 3, 4, A4, A3, 7, 8 }; | |
const int led1_pin = 2; | |
const int led2_pin = 3; | |
const int led3_pin = 4; | |
const int led4_pin = A4; | |
const int led5_pin = A3; | |
const int led6_pin = 7; | |
const int led7_pin = 8; | |
const int r_pin = 9; | |
const int g_pin = 5; | |
const int b_pin = 6; | |
const int hall_pin = A5; | |
int hall_state = 0; | |
int last_hall_state = 0; | |
unsigned long previousMillis = 0; | |
typedef struct { | |
struct { | |
byte r; | |
byte g; | |
byte b; | |
} rgb; | |
unsigned int delaymicros; | |
byte pattern[128]; | |
} POVdata; | |
POVdata pov; | |
void setup() { | |
Serial.begin(57600); | |
pinMode(led1_pin, OUTPUT); | |
pinMode(led2_pin, OUTPUT); | |
pinMode(led3_pin, OUTPUT); | |
pinMode(led4_pin, OUTPUT); | |
pinMode(led5_pin, OUTPUT); | |
pinMode(led6_pin, OUTPUT); | |
pinMode(led7_pin, OUTPUT); | |
pinMode(r_pin, OUTPUT); | |
pinMode(b_pin, OUTPUT); | |
pinMode(g_pin, OUTPUT); | |
pinMode(hall_pin, INPUT); | |
radio.begin(); | |
radio.openReadingPipe(0, address); | |
radio.setPALevel(RF24_PA_MIN); | |
radio.startListening(); | |
} | |
void leds_off() { | |
digitalWrite(led1_pin, LOW); | |
digitalWrite(led2_pin, LOW); | |
digitalWrite(led3_pin, LOW); | |
digitalWrite(led4_pin, LOW); | |
digitalWrite(led5_pin, LOW); | |
digitalWrite(led6_pin, LOW); | |
digitalWrite(led7_pin, LOW); | |
} | |
void set_color_led() { | |
analogWrite(r_pin, pov.rgb.r); | |
analogWrite(g_pin, pov.rgb.g); | |
analogWrite(b_pin, pov.rgb.b); | |
} | |
void loop() { | |
if (radio.available()) { | |
radio.read(&pov, sizeof(pov)); | |
Serial.println("got something"); | |
Serial.println(pov.rgb.r, HEX); | |
Serial.println(pov.rgb.g, HEX); | |
Serial.println(pov.rgb.b, HEX); | |
Serial.println(pov.delaymicros); | |
Serial.println(); | |
for (int i = 0; i < sizeof(pov.pattern); i++) { | |
Serial.print("pattern pos "); | |
Serial.print(i); | |
Serial.print(" "); | |
Serial.println(byte(pov.pattern[i]), BIN); | |
} | |
} | |
hall_state = digitalRead(hall_pin); | |
if (hall_state != last_hall_state) { | |
if (hall_state == HIGH) { | |
set_color_led(); | |
for (int i = 0; i < sizeof(pov.pattern); i++) { | |
for (int l = 0; l < 7; l++) { | |
digitalWrite(led_pins[l], (pov.pattern[i] & (1 << l)) > 0); | |
delayMicroseconds(pov.delaymicros); | |
} | |
} | |
} | |
} | |
leds_off(); | |
last_hall_state = hall_state; | |
} |
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
/* | |
* Read data off the serial port and pipe it over the nRF24 to the pov display | |
*/ | |
#include <SPI.h> | |
#include <nRF24L01.h> | |
#include <RF24.h> | |
RF24 radio(A1, A0); // CE, CSN | |
const byte address[6] = "00001"; | |
typedef struct { | |
struct { | |
byte r; | |
byte g; | |
byte b; | |
} rgb; | |
unsigned int delaymicros; | |
byte pattern[128]; | |
} POVdata; | |
POVdata pov; | |
String inputString = ""; | |
boolean stringComplete = false; | |
void setup() { | |
Serial.begin(57600); | |
inputString.reserve(1800); | |
radio.begin(); | |
radio.openWritingPipe(address); | |
radio.setPALevel(RF24_PA_MIN); | |
radio.stopListening(); | |
} | |
int pos; | |
String untilNextSpace(String str) { | |
int old_pos = pos; | |
pos = str.indexOf(' ', pos); | |
return str.substring(old_pos, pos); | |
} | |
void loop() { | |
if (stringComplete) { | |
pos = 0; | |
pov.rgb.r = byte(untilNextSpace(inputString).toInt()); | |
pos++; | |
pov.rgb.g = byte(untilNextSpace(inputString).toInt()); | |
pos++; | |
pov.rgb.b = byte(untilNextSpace(inputString).toInt()); | |
pos++; | |
pov.delaymicros = untilNextSpace(inputString).toInt(); | |
pos++; | |
inputString.remove(0, pos); | |
memset(pov.pattern, 0, sizeof(pov.pattern)); | |
for (unsigned int i = 0; i < inputString.length() - 1; i++) { | |
pov.pattern[i / 7] <<= 1; | |
pov.pattern[i / 7] |= (inputString.charAt(i) == '1' ? 1 : 0); | |
} | |
// Serial.println(pov.rgb.r, HEX); | |
// Serial.println(pov.rgb.g, HEX); | |
// Serial.println(pov.rgb.b, HEX); | |
// Serial.println(pov.delaymicros); | |
// Serial.println(); | |
for (int i = 0; i < sizeof(pov.pattern); i++) { | |
Serial.print("pattern pos "); | |
Serial.print(i); | |
Serial.print(" "); | |
Serial.println(pov.pattern[i], BIN); | |
} | |
radio.write(&pov, sizeof(pov)); | |
Serial.println("Data sent out over radio"); | |
inputString = ""; | |
stringComplete = false; | |
} | |
} | |
void serialEvent() { | |
while (Serial.available()) { | |
char inChar = (char)Serial.read(); | |
inputString += inChar; | |
if (inChar == '\n') { | |
stringComplete = true; | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment