bsidesbadge/samd/src/main.cpp

96 lines
1.7 KiB
C++

#include <Arduino.h>
#include "RgbDriver.h"
RgbDriver rgbDriver(0b0101000);
int mapLEDIndex(int idx) {
switch(idx) {
case 0: return 1;
case 1: return 0;
case 2: return 7;
case 3: return 6;
case 4: return 5;
case 5: return 4;
case 6: return 3;
case 7: return 2;
default: return -1;
}
}
int r = 255;
int g = 0;
int b = 200;
void setup() {
int idx;
Serial.begin(115200);
delay(5000);
Serial.println("Starting up!");
rgbDriver.selectNormalMode();
rgbDriver.setDeviceConfig(true, true, true, true, false, false);
rgbDriver.setLedConfig(false, false, false, false, false, false, false, false);
Serial.println("Lighting LEDS");
for (int i = 0; i< 8; i++) {
idx = mapLEDIndex(i);
rgbDriver.setLedBrightness(idx, 0x1f);
rgbDriver.setLedColour(idx, r, g, b);
delay(500);
}
Serial.println("LEDS Lit!");
}
void loop() {
int idx;
if (Serial.available()) {
char ch = Serial.read();
switch (ch) {
case 'r':
r += 10;
if (r > 255) {r = 255;}
case 'R':
r -= 10;
if (r < 0) {r=0;}
case 'g':
g += 10;
if (g > 255) {g = 255;}
case 'G':
g -= 10;
if (g < 0) {g=0;}
case 'b':
b += 10;
if (b > 255) {b = 255;}
case 'B':
b -= 10;
if (b < 0) {b=0;}
default:
break;
}
Serial.print("R: "); Serial.print(r);
Serial.print(" B: "); Serial.print(g);
Serial.print(" G: "); Serial.println(b);
for (int i = 0; i<8; i++) {
idx = mapLEDIndex(i);
rgbDriver.setLedBrightness(idx, 0x1f);
rgbDriver.setLedColour(idx, r, g, b);
}
}
}