Robot Security System
Dependencies: Motordriver SHTx mbed
main.cpp
- Committer:
- dmehta39
- Date:
- 2012-10-12
- Revision:
- 0:b6d5c2bbe0a8
File content as of revision 0:b6d5c2bbe0a8:
#include "mbed.h" #include "motordriver.h" //#include "SCP1000.h" #include "TextLCD.h" //#include "sht15.hpp" #include"stdio.h" #include "stdlib.h" #include "SHTx/sht15.hpp" Serial pc(USBTX, USBRX); // tx, rx Serial device(p13, p14); // tx, rx DigitalOut myled3(LED3); DigitalOut myled2(LED2); DigitalOut myled4(LED4); SHTx::SHT15 sensor(p9, p10); float ss=0; Motor left(p21, p22, p23, 1); // pwm, fwd, rev, has brake feature Motor right(p26, p25, p24, 1); float dhaval=0; float jill=0; float g=0; float g1=0; float g2=0; float g3=0; //char buffer[50]; float h=0; float h1=0; float h2=0; float h3=0; TextLCD lcd(p15, p16, p17, p18, p19, p20); char a[300]; int count=0; int s = 0; DigitalOut busy(LED1); int main() { sensor.setOTPReload(false); sensor.setResolution(true); busy = true; sensor.update(); busy = false; sensor.setScale(false); float pp1 = (sensor.getTemperature()-2.0); char halftemp[60]; sprintf(halftemp, "%f", pp1); float pp2 = sensor.getHumidity(); char halftemp2[60]; sprintf(halftemp2, "%f", pp2); do{ while(1) { count = 0; if (device.readable()) { do { s=device.getc(); a[count]=s; count++; } while(s != '\r'); if(a[6]=='9' && a[7]=='0' && a[8]=='2' && a[9]=='8' && a[10]=='7' && a[11]=='8' && a[12]=='0' && a[13]=='7' && a[14]=='2' ) { lcd.cls(); lcd.printf("Temperature in C: %s\n", halftemp); myled3=!myled3; h1=0;h2=0;h3=0;g1=0;g2=0;g3=0; while (1) { if(g1==0) { // Sweep the motor speed from full-speed reverse (-1.0) to full speed forwards (1.0) left.speed(0.4); right.speed(0.8); wait(0.5); // Turn off motors - coast one and brake one right.speed(0); //////for turning right...... left.speed(0); ////for turning left ++g1; wait(1); } if(g2==0 ) { // Sweep the motor speed from full-speed reverse (-1.0) to full speed forwards (1.0) left.speed(0.2); right.speed(0); wait(1); // Turn off motors - coast one and brake one left.stop(0); ////for turning left ++g2; wait(1); } if(g3==0) { // Sweep the motor speed from full-speed reverse (-1.0) to full speed forwards (1.0) left.speed(0.4); right.speed(0.8); wait(0.5); // Turn off motors - coast one and brake one right.speed(0); //////for turning right...... left.speed(0); ////for turning left ++g3; ++jill; wait(1); } if(jill==1) break; } } /////////////// TESTING SECOND CARD...F0RWARD THEN RIGHT TURN TERN BACK if(a[6]=='9' && a[7]=='0' && a[8]=='2' && a[9]=='9' && a[10]=='1' && a[11]=='1' && a[12]=='2' && a[13]=='5' && a[14]=='0' ) { lcd.cls(); lcd.printf("Humidity is\n: %s %%\n", halftemp2); myled2=!myled2; myled4=!myled4; g1=0;g2=0;g3=0; h1=0;h2=0;h3=0; while (1) { if(h1==0 ) { // Sweep the motor speed from full-speed reverse (-1.0) to full speed forwards (1.0) left.speed(0.4); right.speed(0.8); wait(0.5); // Turn off motors - coast one and brake one right.speed(0); //////for turning right...... left.speed(0); ////for turning left ++h1; g1=0; wait(1); } if(h2==0 ) { // Sweep the motor speed from full-speed reverse (-1.0) to full speed forwards (1.0) right.speed(0.2); left.speed(0); wait(1); // Turn off motors - coast one and brake one right.stop(0); //////for turning right...... //left.stop(0); ////for turning left ++h2; g2=0; wait(1); } if(h3==0) { //myled=1; // Sweep the motor speed from full-speed reverse (-1.0) to full speed forwards (1.0) left.speed(0.4); wait(0.5); // Turn off motors - coast one and brake one right.speed(0); //////for turning right...... left.speed(0); ////for turning left ++h3; g3=0; ++dhaval; wait(1); } if(dhaval==1) break; } } } } } while(ss==0); }