diff --git a/rack/controller/controller.ino b/rack/controller/controller.ino new file mode 100644 index 0000000..f977bf6 --- /dev/null +++ b/rack/controller/controller.ino @@ -0,0 +1,52 @@ +#include + +#define NUMPIXELS 32 +#define PIN 0 + + +#define NEO_PIN 0 +#define FAN_PIN 1 +#define TEMP_PIN 2 +#define PANEL_PIN TX + + +Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800); +unsigned long lastTime = 0; +uint8_t line[8 * 3]; + +void setup() { + Serial.begin(9600); + + // put your setup code here, to run once: + pixels.begin(); + + pinMode(PANEL_PIN, INPUT_PULLUP); + pinMode(TEMP_PIN, INPUT); + pinMode(FAN_PIN, OUTPUT); +} + + + +void loop() { + /* if(Serial.available() > 0) { */ + /* uint8_t row = Serial.read(); */ + /* Serial.readBytes(line, 8*3); */ + + /* if(digitalRead(PANEL_PIN) == LOW) { // Front panel in place */ + /* for(uint8_t i = 0; i < 8; ++i) { */ + /* uint8_t * color = line + 3 * i; */ + /* pixels.setPixelColor(row * 8 + i, color[0], color[1], color[2]); */ + /* } */ + /* pixels.show(); */ + /* } */ + /* } */ + + unsigned long now = millis(); + unsigned long timeChange = (now - lastTime); + if(timeChange >= 1000) { // Update not more than once per second + int temp = analogRead(TEMP_PIN); + uint8_t speed = map(val, 0, 1023, 0, 255); + analogWrite(FAN_PIN, speed); + lastTime = now; + } +}