Signori, questo è il codice di doukietown...... divertitevi
Dependencies: HCSR04 TCS3200 X_NUCLEO_IHM12A1 mbed
Fork of HelloWorld_IHM12A1 by
Revision 7:b0ba8a7b6e9f, committed 2017-04-05
- Comitter:
- LorenzoCR
- Date:
- Wed Apr 05 08:36:05 2017 +0000
- Parent:
- 6:bd2fa888c101
- Commit message:
- hallo
Changed in this revision
diff -r bd2fa888c101 -r b0ba8a7b6e9f HCSR04.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HCSR04.lib Wed Apr 05 08:36:05 2017 +0000 @@ -0,0 +1,1 @@ +http://developer.mbed.org/users/prabhuvd/code/HCSR04/#71da0dbf4400
diff -r bd2fa888c101 -r b0ba8a7b6e9f TCS3200.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TCS3200.lib Wed Apr 05 08:36:05 2017 +0000 @@ -0,0 +1,1 @@ +http://developer.mbed.org/users/wingblank/code/TCS3200/#9edf5a7e29e6
diff -r bd2fa888c101 -r b0ba8a7b6e9f main.cpp --- a/main.cpp Fri Mar 24 14:13:53 2017 +0000 +++ b/main.cpp Wed Apr 05 08:36:05 2017 +0000 @@ -40,9 +40,15 @@ /* mbed specific header files. */ #include "mbed.h" +#include "color.h" +#include "hcsr04.h" +#include "BDCMotor.h" /* Component specific header files. */ #include "STSpin240_250.h" +HCSR04 sensor1(D10, D11); + +ColorSensor color(D4, D5, D6, D7, D8); /* Variables -----------------------------------------------------------------*/ @@ -111,7 +117,6 @@ int main() { - uint8_t demoStep = 0; /* Printing to the console. */ printf("STARTING MAIN PROGRAM\r\n"); @@ -155,126 +160,49 @@ /* Infinite Loop. */ printf("--> Infinite Loop...\r\n"); + bool fase = 1; while (true) { - switch (demoStep) { - case 0: { - printf("STEP 0: Motor(0) FWD Speed=100%% - Motor(1) Inactive\r\n"); - /* Set speed of motor 0 to 100 % */ - motor->set_speed(0,100); - /* start motor 0 to run forward*/ - /* if chip is in standby mode */ - /* it is automatically awakened */ - motor->run(0, BDCMotor::FWD); - break; - } - case 1: { - printf("STEP 1: Motor(0) FWD Speed=75%% - Motor(1) BWD Speed=100%%\r\n"); - /* Set speed of motor 0 to 75 % */ - motor->set_speed(0,75); - /* Set speed of motor 1 to 100 % */ - motor->set_speed(1,100); - /* start motor 1 to run backward */ - motor->run(1, BDCMotor::BWD); - break; - } - case 2: { - printf("STEP 2: Motor(0) FWD Speed=50%% - Motor(1) BWD Speed=75%%\r\n"); - /* Set speed of motor 0 to 50 % */ - motor->set_speed(0,50); - /* Set speed of motor 1 to 75% */ - motor->set_speed(1,75); - break; - } - case 3: { - printf("STEP 3: Motor(0) FWD Speed=25%% - Motor(1) BWD Speed=50%%\r\n"); - /* Set speed of motor 0 to 25 % */ - motor->set_speed(0,25); - /* Set speed of motor 1 to 50% */ - motor->set_speed(1,50); - break; - } - case 4: { - printf("STEP 4: Motor(0) Stopped - Motor(1) BWD Speed=25%%\r\n"); - /* Stop Motor 0 */ - motor->hard_stop(0); - /* Set speed of motor 1 to 25% */ - motor->set_speed(1,25); - break; - } - case 5: { - printf("STEP 5: Motor(0) BWD Speed=25%% - Motor(1) Stopped\r\n"); - /* Set speed of motor 0 to 25 % */ - motor->set_speed(0,25); - /* start motor 0 to run backward */ - motor->run(0, BDCMotor::BWD); - /* Stop Motor 1 */ - motor->hard_stop(1); - break; - } - case 6: { - printf("STEP 6: Motor(0) BWD Speed=50%% - Motor(1) FWD Speed=25%%\r\n"); - /* Set speed of motor 0 to 50 % */ + motor->run(0, BDCMotor::FWD); + motor->run(1, BDCMotor::FWD); + motor->set_speed(1,49); + motor->set_speed(0,50); + sensor1.start(); + if (sensor1.get_dist_cm() < 10){ + fase = !fase; + if (fase == 0){ + wait_ms(2500); + motor->set_speed(1,15); + motor->set_speed(0,50); + wait_ms(500); + motor->set_speed(1,49); motor->set_speed(0,50); - /* Set speed of motor 1 to 25 % */ - motor->set_speed(1,25); - /* start motor 1 to run backward */ - motor->run(1, BDCMotor::FWD); - break; - } - case 7: { - printf("STEP 7: Motor(0) BWD Speed=75%% - Motor(1) FWD Speed=50%%\r\n"); - /* Set speed of motor 0 to 75 % */ - motor->set_speed(0,75); - /* Set speed of motor 1 to 50 % */ - motor->set_speed(1,50); - break; - } - case 8: { - printf("STEP 8: Motor(0) BWD Speed=100%% - Motor(1) FWD Speed=75%%\r\n"); - /* Set speed of motor 0 to 100 % */ - motor->set_speed(0,100); - /* Set speed of motor 1 to 75 % */ - motor->set_speed(1,75); - break; - } - case 9: { - printf("STEP 9: Motor(0) BWD Speed=100%% - Motor(1) FWD Speed=100%%\r\n"); - /* Set speed of motor 1 to 100 % */ - motor->set_speed(1,100); - break; - } - case 10: { - printf("STEP 10\r\n: Stop both motors and disable bridges\r\n"); - /* Stop both motors and disable bridge */ - motor->hard_hiz(0); - motor->hard_hiz(1); - break; - } - case 11: { - printf("STEP 11: Motor(0) FWD Speed=100%% - Motor(1) FWD Speed=100%%\r\n"); - /* Start both motors to go forward*/ - motor->run(0,BDCMotor::FWD); - motor->run(1,BDCMotor::FWD); - break; - } - case 12: - default: { - printf("STEP 12: Stop both motors and enter standby mode\r\n"); - /* Stop both motors and put chip in standby mode */ - motor->reset(); - break; - } - } - - /* Wait for 5 seconds */ - wait_ms(5000); - - /* Increment demostep*/ - demoStep++; - if (demoStep > 12) { - demoStep = 0; - } - } + } + else + { + wait_ms(2500); + motor->set_speed(1,50); + motor->set_speed(0,15); + wait_ms(500); + motor->set_speed(1,49); + motor->set_speed(0,50); + } + } + + if(color.getRed()>100&&color.getGreen()>100) + { + //se vede il giallo allora fa questo + } + if(color.getRed()>130&&color.getGreen()>130&&color.getBlue()>130){ + //se vede il bianco allora fa questo + unsigned int motorino= + } + if(color.getRed()>110){ + //se vede il rosso + motor->hard_stop(0); + motor->hard_stop(1); + wait(2); + } + } } -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ +/*********** (C) COPYRIGHT STMicroelectronics ********** END OF FILE **********/
diff -r bd2fa888c101 -r b0ba8a7b6e9f mbed.bld --- a/mbed.bld Fri Mar 24 14:13:53 2017 +0000 +++ b/mbed.bld Wed Apr 05 08:36:05 2017 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mbed_official/code/mbed/builds/082adc85693f \ No newline at end of file +http://mbed.org/users/mbed_official/code/mbed/builds/856d2700e60b \ No newline at end of file