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
main.cpp
- Committer:
- arb
- Date:
- 2017-05-01
- Revision:
- 3:a7bd2f5946ed
- Parent:
- 2:69a3683834c7
File content as of revision 3:a7bd2f5946ed:
#include "mbed.h" #include "rtos.h" #include "Motor.h" Serial pc(USBTX, USBRX); DigitalOut led1(LED1); DigitalOut led2(LED2); DigitalOut led3(LED3); DigitalOut led4(LED4); DigitalIn Switch(p15); //SERVO for arm PwmOut arm(p26); //LEDS PwmOut red(p25); PwmOut green(p24); PwmOut blue(p23); DigitalOut MouthUp(p11); DigitalOut MouthDown(p12); DigitalOut MouthCenter(p10); //SD card/audio PwmOut Speaker(p22); /* //For SD custom songs AnalogOut DACout(p18); SDFileSystem sd(p5, p6, p7, p8, "sd"); // the pinout on the mbed Cool Components workshop board wave_player waver(&DACout,&Speaker); char buffer[20]; FILE *wave_file; */ //motor for wheels Motor wheel(p21, p6, p5); // pwm, fwd, rev Thread t2; // LED Color Thread t3; // Speaker Music / Audio Thread t4; // Motor Control Mutex state; int angerlevel; int priority=1; bool pushFlag = false; void LEDThread() { //TODO: Add colors according to angerlevel while(1){ if (pushFlag&&priority==1) { state.lock(); //lock to read the angerlevel switch(angerlevel){ case 1: //turn on leds MouthCenter=1; MouthUp=1; red=1.0; green=1.0; blue=1.0; break; case 2: //LEDS/AUDIO red=1.0; green=0.0; blue=1.0; MouthUp=0; break; case 3: MouthDown=1; red=1.0; green=0.0; blue=0.0; break; default: //case 0 do nothing break; } priority=2; state.unlock(); } } } void AudioThread() { //PWM/AMP? to play audio? //TODO: get sound on SD card and confirm this will work //mabye multiple sounds according to what angerlevel while(1){ if (pushFlag&&priority==2) { state.lock(); //lock to read the angerlevel switch(angerlevel){ case 2: //AUDIO /*for SD custom sound for (int a=1;a<40; a++){ sprintf(buffer,"/sd//voice%d.wav",a); wave_file=fopen(buffer,"r"); waver.play(wave_file); fclose(wave_file); }*/ //siren affect arm.period(1.0/800.0); Speaker = float(48)/50.0; wait(2.5); Speaker=0; break; case 3: break; default: //Nothing to do here break; } priority=3; state.unlock(); } } } void WheelsThread() { //Drive around randomly //TODO: add random driving for both motors(current:example for 1 motor) while(1){ if (pushFlag&&priority==3) { state.lock(); //lock to read the angerlevel switch(angerlevel){ case 3: arm.period(0.001); wheel.speed(1.0); wait(2.5); arm.period(1.0/969.0); Speaker = float(46)/50.0; wait(.5); arm.period(1.0/800.0); wait(.5); arm.period(0.001); wheel.speed(-1.0); wait(2.5); arm.period(1.0/969.0); Speaker = float(48)/50.0; wait(.5); arm.period(1.0/800.0); wait(.5); Speaker=0; arm.period(0.001); wheel.speed(0.0); wait(0.04); break; default: //nothing break; } priority=1; state.unlock(); } } } void fallInterrupt(){ priority=1; pushFlag=true; } void init(){ //start threads t2.start(LEDThread); t3.start(AudioThread); t4.start(WheelsThread); } int main() { init(); while(1) { while(Switch) { //* code } fallInterrupt(); //start servo state.lock(); //lock for period + angerlevel arm.period(0.020); // servo requires a 20ms period arm.pulsewidth(0.002); wait(0.5); arm.pulsewidth(0.0013); wait(0.5); angerlevel++; state.unlock(); wait(1); pushFlag=false; } pc.printf("exited"); }