Random walk for psiSwarm
Dependencies: PsiSwarmV8_CPP mbed
Fork of PsiSwarm_V8_Blank_CPP by
Revision 3:5d11c69d95df, committed 2017-08-03
- Comitter:
- alixander
- Date:
- Thu Aug 03 13:00:02 2017 +0000
- Parent:
- 2:5d37e5fd7141
- Commit message:
- Random walk for PsiSwarm
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 5d37e5fd7141 -r 5d11c69d95df main.cpp --- a/main.cpp Mon Oct 17 13:20:23 2016 +0000 +++ b/main.cpp Thu Aug 03 13:00:02 2017 +0000 @@ -14,6 +14,7 @@ /// Include main.h - this includes psiswarm.h all the other necessary core files #include "main.h" +#include <cstdlib> Psiswarm psi; @@ -21,12 +22,34 @@ char * author_name = "YRL"; char * version_name = "0.80"; +Timer t; //set a timer +int how_long; + ///User code loop: This is where user code should go; it is run as an infinite loop void user_code_loop() { - // Example: - // animations.led_run1(); - // wait(1.2); + motors.forward(0.2); //simple code, the psiswarm continues forwards + led.set_leds(0b10101010,0b01010101); //illuminate circumference with alternating led pattern + + t.start(); + how_long = t.read(); + + if(how_long > 1) { + float turn = (rand()%6)/10.0f - 0.25; + //float turn = + + char s1[17]; + + sprintf(s1,"%.3f",turn); + display.clear_display(); + display.set_position(0,0); + display.write_string(s1); + + motors.turn(turn); + wait(1); + t.reset(); + } + } ///Place user code here that should be run after initialisation but before the main loop @@ -35,7 +58,7 @@ wait(1); display.clear_display(); display.set_position(0,0); - display.write_string("No Code"); + display.write_string("Going for a walk..."); //display 'Going for a walk...' to indicate robot's function } /// Code goes here to handle what should happen when the user switch is pressed