forked from letsRobot/letsrobot
-
Notifications
You must be signed in to change notification settings - Fork 20
LED Bot
Brooke Morrison edited this page Sep 27, 2021
·
8 revisions
LED bot is the little diode that could.
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
#define RED 6
#define GREEN 9
#define BLUE 10
#define MIN 0
#define MAX 255
int redVal = 0;
int greenVal = 0;
int blueVal = 0;
int brightnessStep = 25;
void setup() {
Serial.begin(9600);
pinMode(RED, OUTPUT);
pinMode(GREEN, OUTPUT);
pinMode(BLUE, OUTPUT);
}
void loop() {
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 something
if(Serial.available() % 2 == 1) {
Serial.end();
Serial.begin(9600);
}
}
void redUp() {
redVal = threshold(redVal + brightnessStep);
}
void greenUp() {
greenVal = threshold(greenVal + brightnessStep);
}
void blueUp() {
blueVal = threshold(blueVal + brightnessStep);
}
void redDown() {
redVal = threshold(redVal - brightnessStep);
}
void greenDown() {
greenDown = threshold(greenVal - brightnessStep);
}
void blueDown() {
blueDown = threshold(blueVal - brightnessStep);
}
int threshold(int val) {
if (val < MIN) {
return MIN;
} else if (val > MAX) {
return MAX;
}
return val;
}
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
.
- Adafruit Motor Hat
- Adafruit PWM / Servo Hat
- Anki Cozmo on MacOS/Linux
- Anki Cozmo on Windows
- Cytron MDD10 10 Amp Motor Driver
- GoPiGo2
- GoPiGo3
- L298N Dual Motor Driver
- MAX7219 SPI LED Driver
- MotoZero 4 Motor Controller
- MQTT Publish Controller
- OWI 535 Robotic Arm (USB Controller)
- Serial Based Controllers (Parallaxy or Arduinos)
- PiBorg ThunderBorg Motor Driver
- Pololu Daul MC33926 Motor Driver (experimental)
- Pololu DRV8835 Dual Motor Driver
- Pololu Maestro Servo Controller (experimental)