Dependencies: mbed Motor mbed-rtos
Useless Robot
Useless Robot Overview
Project by Austin Bartmess and Jeremy Deremer
This is a robot developed on an ARM Microcontroller (LPC 1768). It uses a servo, two DC motors both powered by an external power source, nine red LEDs, two RBG LEDs, a speaker, a toggle switch and a transistor.
The goal of this robot is to stay off. However, the user can turn it on without harm. It attempts to stay off via turning a toggle switch off with an arm attached to a servo. If the robot is turned on too much, it will progressively get angry. It starts by not smiling and changing eye colors. Following that, the robot will frown and yell at the user. Finally, the robot will drive around randomly while screaming and looking angry via its LEDs.
Required Parts
- mbed Microcontroller x1
- USB to mini USB cable x1
- Servo x1
- H-Bridge Breakout Board x1
- DC Motors x2
- DC Motor Wheels x4
- Red LEDs x9
- RGB LEDs x2
- 0.5W Speaker x1
- Toggle Switch x1
- BJTransistor x1
- Jumper Cables Kit x1
- Breadboard x2
Pinout and Connections
Mbed | H-Bridge | DC Motors | Servo | Transistor | Speaker | LEDs | Barrel Jack | Toggle Switch |
---|---|---|---|---|---|---|---|---|
GND | GND | (-) | Emitter | (-) | GND | (-) | (-) | |
Vu | ||||||||
Vin | Vm | (+) | (+) | |||||
Vout | Vcc, /STBY | (+) | ||||||
p5 | AIN1 | |||||||
p6 | AIN2 | |||||||
p10 | LED+ | |||||||
p11 | LED+ | |||||||
p12 | LED+ | |||||||
p15 | Control | |||||||
p21 | PWMA | |||||||
p22 | Collector | |||||||
p23 | Blue | |||||||
p24 | Green | |||||||
p25 | Red | |||||||
p26 | Control | |||||||
AO1 | (+) | |||||||
AO2 | (-) |
Demo Clip
Source Code
Diff: main.cpp
- Revision:
- 1:0402db7e91f5
- Parent:
- 0:4931c25e1cf7
- Child:
- 2:69a3683834c7
--- a/main.cpp Wed Apr 26 20:21:54 2017 +0000 +++ b/main.cpp Wed Apr 26 21:14:28 2017 +0000 @@ -10,7 +10,8 @@ // RGBLed myRGBled(p21,p22,p23); //RGB PWM pins -Serial bluemod(p28,p27); +InterruptIn Switch(p15); + PwmOut red(p21); PwmOut green(p22); PwmOut blue(p23); @@ -22,68 +23,99 @@ Thread t3; // Speaker Music / Audio Thread t4; // Motor Control -Mutex lk_LCD; - -void rgb_t3() { - - while (true) { - - } -} +Mutex state; +int angerlevel; -void lcd_t1() { - while (true) { - for (int i = 0; i < 10; i++) - { - lk_LCD.lock(); - uLCD.locate(2,2); - uLCD.printf("\n Hello World! \nCount by one is %d!\n", i); - lk_LCD.unlock(); - Thread::wait(1000); - } +bool pushFlag = false; + +void ArmThread() +{ + //basic if switch is toggled then use arm to turn it off + //Want to add delay depedning on anger level + //Potentially need a queue system + if (pushFlag) + { + //start servo + state.lock(); //lock to update the anger level + angerlevel++; + state.unlock(); } } -void lcd_t2() { - while (true) { - for (int j = 0; j < 20; j += 2) - { - lk_LCD.lock(); - uLCD.locate(4,4); - uLCD.printf("\n Hello World! \nCount by two is %d!\n", j); - lk_LCD.unlock(); - Thread::wait(2000); - } - } +void LEDThread() { + state.lock(); //lock to read the angerlevel + switch(angerlevel) + case 1: + state.unlock(); + //turn on leds + break; + case 2: + state.unlock(); + //LEDS/AUDIO + break; + case 3: + state.unlock(); + //LEDS/AUDIO/motor + break; + default: + state.unlock(); + //case 0 do nothing + break; + state.unlock(); } + +void AudioThread() { + //PWM/AMP? to play audio? + //need to get sd card & angry sounds for audio + state.lock(); //lock to read the angerlevel + switch(angerlevel) + case 2: + state.unlock(); + //AUDIO + break; + case 3: + state.unlock(); + //AUDIO/MOTOR + break; + default: + state.unlock(); + //Nothing to do here + break; + state.unlock(); +} + +void WheelsThread() { + //Drive around randomly + state.lock(); //lock to read the angerlevel + switch(angerlevel) + case 3: + state.unlock(); + //MOTOR + break; + default: + state.unlock(); + //nothing + break; + state.unlock(); +} + - +void fallInterrupt(){ + pushFlag=true; +} + +void init(){ + interrupt.fall(&fallInterrupt); + interrupt.mode(PullUp); + +} int main() { - // myRGBled.write(0.0, 0.0, 0.0); - char bred=0; - char bgreen=0; - char bblue=0; - red = green = blue = 0; - - t3.start(rgb_t3); - t1.start(lcd_t1); - t2.start(lcd_t2); + init(); + + t1.start(ArmThread); + t2.start(LEDThread); + t3.start(AudioThread); + t4.start(WheelsThread); - while (true) { - if (bluemod.getc()=='!') { - if (bluemod.getc()=='C') { //color data packet - bred = bluemod.getc(); // RGB color values - bgreen = bluemod.getc(); - bblue = bluemod.getc(); - if (bluemod.getc()==char(~('!' + 'C' + bred + bgreen + bblue))) { //checksum OK? - red = bred/255.0; //send new color to RGB LED PWM outputs - green = bgreen/255.0; - blue = bblue/255.0; - } - } - } - led1 = !led1; - Thread::wait(500); - } } \ No newline at end of file