Skip to content
Brooke Morrison edited this page Sep 27, 2021 · 8 revisions

LED bot is the little diode that could.

Hardware Configuration

The following hardware is required to make an accurate clone of LED bot.

  • Raspberry Pi 3b or above.
  • Arduino with at least 1 serial port, capable of delivering 80 mA through 3 PWM pins. I used an Uno Rev 3.
  • Breadboard
  • RGB LED
  • Resistors
  • Hookup wire
  • USB for powering Arduino and sending serial data

The code

#defineRED6
#defineGREEN9
#defineBLUE10
#defineMIN0
#defineMAX255int redVal = 0;
int greenVal = 0;
int blueVal = 0;
int brightnessStep = 25;
voidsetup() {
Serial.begin(9600);
pinMode(RED, OUTPUT);
pinMode(GREEN, OUTPUT);
pinMode(BLUE, OUTPUT);
}
voidloop() {
if (Serial.available() >= 2) {
for (int i = 0; i < 2; i++) {
command[i] = Serial.read();
}
switch(command[1]) {
case'd':
switch(command[0]) {
case'r':
redDown();
break;
case'g':
greenDown();
break;
case'b':
blueDown();
break;
}
break;
case'u':
switch(command[0]) {
case'r':
redUp();
break;
case'g':
greenUp();
break;
case'b':
blueUp();
break;
}
break;
default:
break;
}
}
analogWrite(RED, redVal);
analogWrite(GREEN, greenVal);
analogWrite(BLUE, blueVal);
// Clear the buffer if there's some weird data or somethingif(Serial.available() % 2 == 1) {
Serial.end();
Serial.begin(9600);
}
}
voidredUp() {
redVal = threshold(redVal + brightnessStep);
}
voidgreenUp() {
greenVal = threshold(greenVal + brightnessStep);
}
voidblueUp() {
blueVal = threshold(blueVal + brightnessStep);
}
voidredDown() {
redVal = threshold(redVal - brightnessStep);
}
voidgreenDown() {
greenDown = threshold(greenVal - brightnessStep);
}
voidblueDown() {
blueDown = threshold(blueVal - brightnessStep);
}
intthreshold(int val) {
if (val < MIN) {
returnMIN;
} elseif (val > MAX) {
returnMAX;
}
return val;
}

Controller Configuration

I don't use a microphone for LEDBot. A loopback is enabled instead.

sudo modprobe snd-aloop
sudo echo'snd-aloop'>> /etc/modules

For the current session, the device will show up as card 1, but after a reboot it'll show up as card 0.

I set my microphone device to 0,0 and my speaker device to 0,1.

Clone this wiki locally