![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
not sure on the if statement at the bottom
Dependencies: ContinuousServo TCS3472_I2C Tach mbed
Fork of ES202_Final_ColorSensor by
color.cpp@2:b5a85ba07057, 2018-04-30 (annotated)
- Committer:
- PlayaLarrea
- Date:
- Mon Apr 30 15:38:53 2018 +0000
- Revision:
- 2:b5a85ba07057
- Parent:
- 1:1dd468e2ad40
gay
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
PlayaLarrea | 0:7d319151aaa0 | 1 | #include "mbed.h" |
PlayaLarrea | 0:7d319151aaa0 | 2 | #include "ContinuousServo.h" |
PlayaLarrea | 0:7d319151aaa0 | 3 | #include "Tach.h" |
PlayaLarrea | 0:7d319151aaa0 | 4 | #include "TCS3472_I2C.h" |
PlayaLarrea | 0:7d319151aaa0 | 5 | |
PlayaLarrea | 2:b5a85ba07057 | 6 | //InterruptIn hall_sensor(p21); |
PlayaLarrea | 2:b5a85ba07057 | 7 | DigitalOut hallpwr(p22); |
PlayaLarrea | 2:b5a85ba07057 | 8 | DigitalIn hall(p21); |
PlayaLarrea | 0:7d319151aaa0 | 9 | BusOut flash(LED1, LED2, LED3, LED4); |
PlayaLarrea | 0:7d319151aaa0 | 10 | TCS3472_I2C rgb_sensor(p9, p10); |
PlayaLarrea | 0:7d319151aaa0 | 11 | ContinuousServo left(p23); //Set up left wheel driver |
PlayaLarrea | 0:7d319151aaa0 | 12 | ContinuousServo right(p26); //Set up right wheel driver |
PlayaLarrea | 0:7d319151aaa0 | 13 | |
PlayaLarrea | 1:1dd468e2ad40 | 14 | int rgb_data[4]; |
PlayaLarrea | 1:1dd468e2ad40 | 15 | float PWMbrightness = 1.0; |
PlayaLarrea | 1:1dd468e2ad40 | 16 | float LB = 0.0; |
PlayaLarrea | 2:b5a85ba07057 | 17 | int x = 0.0; |
PlayaLarrea | 0:7d319151aaa0 | 18 | |
PlayaLarrea | 2:b5a85ba07057 | 19 | //void mine() { |
PlayaLarrea | 2:b5a85ba07057 | 20 | // flash = 8.0; |
PlayaLarrea | 2:b5a85ba07057 | 21 | // wait(1.0); |
PlayaLarrea | 2:b5a85ba07057 | 22 | // flash = 0; |
PlayaLarrea | 2:b5a85ba07057 | 23 | //} |
PlayaLarrea | 0:7d319151aaa0 | 24 | |
PlayaLarrea | 0:7d319151aaa0 | 25 | int main() { |
PlayaLarrea | 0:7d319151aaa0 | 26 | |
PlayaLarrea | 2:b5a85ba07057 | 27 | hall.mode(PullUp); |
PlayaLarrea | 2:b5a85ba07057 | 28 | // hall_sensor.rise(&mine); |
PlayaLarrea | 2:b5a85ba07057 | 29 | // hall_sensor.fall(&mine); |
PlayaLarrea | 2:b5a85ba07057 | 30 | hallpwr = 1; |
PlayaLarrea | 0:7d319151aaa0 | 31 | |
PlayaLarrea | 1:1dd468e2ad40 | 32 | rgb_sensor.enablePowerAndRGBC(); |
PlayaLarrea | 1:1dd468e2ad40 | 33 | rgb_sensor.setIntegrationTime(100); |
PlayaLarrea | 1:1dd468e2ad40 | 34 | |
PlayaLarrea | 0:7d319151aaa0 | 35 | while(1) { // wait around, interrupts will interrupt this! |
PlayaLarrea | 2:b5a85ba07057 | 36 | |
PlayaLarrea | 2:b5a85ba07057 | 37 | x = hall.read(); |
PlayaLarrea | 2:b5a85ba07057 | 38 | |
PlayaLarrea | 2:b5a85ba07057 | 39 | if(x == 1){ |
PlayaLarrea | 2:b5a85ba07057 | 40 | flash = 8.0; |
PlayaLarrea | 2:b5a85ba07057 | 41 | } |
PlayaLarrea | 2:b5a85ba07057 | 42 | else{ |
PlayaLarrea | 2:b5a85ba07057 | 43 | flash = 0.0; |
PlayaLarrea | 2:b5a85ba07057 | 44 | } |
PlayaLarrea | 2:b5a85ba07057 | 45 | x = hall.read(); |
PlayaLarrea | 2:b5a85ba07057 | 46 | |
PlayaLarrea | 2:b5a85ba07057 | 47 | left.speed(0.1); //Move the left wheel |
PlayaLarrea | 2:b5a85ba07057 | 48 | right.speed(-0.1); //Move the right wheel |
PlayaLarrea | 0:7d319151aaa0 | 49 | |
PlayaLarrea | 1:1dd468e2ad40 | 50 | LB = PWMbrightness; |
PlayaLarrea | 1:1dd468e2ad40 | 51 | rgb_sensor.getAllColors(rgb_data); |
PlayaLarrea | 2:b5a85ba07057 | 52 | |
PlayaLarrea | 2:b5a85ba07057 | 53 | //if(rgb_data[1]>650){ |
PlayaLarrea | 2:b5a85ba07057 | 54 | if(rgb_data[0]>1000 && rgb_data[1]>650 && rgb_data[2]<300 && rgb_data[3]<300){ |
PlayaLarrea | 2:b5a85ba07057 | 55 | flash = 1.0; //red |
PlayaLarrea | 0:7d319151aaa0 | 56 | } |
PlayaLarrea | 2:b5a85ba07057 | 57 | //else if(rgb_data[2]>650){ |
PlayaLarrea | 2:b5a85ba07057 | 58 | else if(rgb_data[0]>900 && rgb_data[1]<700 && rgb_data[2]>650 && rgb_data[3]<700){ |
PlayaLarrea | 2:b5a85ba07057 | 59 | flash = 2.0; //green |
PlayaLarrea | 1:1dd468e2ad40 | 60 | } |
PlayaLarrea | 2:b5a85ba07057 | 61 | //else if(rgb_data[3]>300){ |
PlayaLarrea | 2:b5a85ba07057 | 62 | else if(rgb_data[0]>900 && rgb_data[1]<300 && rgb_data[2]<300 && rgb_data[3]>300){ |
PlayaLarrea | 2:b5a85ba07057 | 63 | flash = 4.0; //blue |
PlayaLarrea | 1:1dd468e2ad40 | 64 | } |
PlayaLarrea | 0:7d319151aaa0 | 65 | } |
PlayaLarrea | 0:7d319151aaa0 | 66 | } |