Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: PsiSwarm-Headstart mbed
Fork of PsiSwarm_V41 by
main.cpp@1:f6356cf1cefc, 2015-10-03 (annotated)
- Committer:
 - jah128
 - Date:
 - Sat Oct 03 23:09:10 2015 +0000
 - Revision:
 - 1:f6356cf1cefc
 - Parent:
 - 0:8a5497a2e366
 - Child:
 - 2:a6214fd156ff
 
Added software version
Who changed what in which revision?
| User | Revision | Line number | New contents of line | 
|---|---|---|---|
| jah128 | 0:8a5497a2e366 | 1 | /*********************************************************************** | 
| jah128 | 0:8a5497a2e366 | 2 | ** ██████╗ ███████╗██╗███████╗██╗ ██╗ █████╗ ██████╗ ███╗ ███╗ ** | 
| jah128 | 0:8a5497a2e366 | 3 | ** ██╔══██╗██╔════╝██║██╔════╝██║ ██║██╔══██╗██╔══██╗████╗ ████║ ** | 
| jah128 | 0:8a5497a2e366 | 4 | ** ██████╔╝███████╗██║███████╗██║ █╗ ██║███████║██████╔╝██╔████╔██║ ** | 
| jah128 | 0:8a5497a2e366 | 5 | ** ██╔═══╝ ╚════██║██║╚════██║██║███╗██║██╔══██║██╔══██╗██║╚██╔╝██║ ** | 
| jah128 | 0:8a5497a2e366 | 6 | ** ██║ ███████║██║███████║╚███╔███╔╝██║ ██║██║ ██║██║ ╚═╝ ██║ ** | 
| jah128 | 0:8a5497a2e366 | 7 | ** ╚═╝ ╚══════╝╚═╝╚══════╝ ╚══╝╚══╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═╝ ** | 
| jah128 | 0:8a5497a2e366 | 8 | ************************************************************************ | 
| jah128 | 0:8a5497a2e366 | 9 | **(C) Dr James Hilder - York Robotics Laboratory - University of York ** | 
| jah128 | 0:8a5497a2e366 | 10 | ***********************************************************************/ | 
| jah128 | 0:8a5497a2e366 | 11 | |
| jah128 | 1:f6356cf1cefc | 12 | /// PsiSwarm Example Main File | 
| jah128 | 0:8a5497a2e366 | 13 | |
| jah128 | 1:f6356cf1cefc | 14 | /// Include psiswarm.h - this includes all the other necessary core files | 
| jah128 | 0:8a5497a2e366 | 15 | #include "psiswarm.h" | 
| jah128 | 0:8a5497a2e366 | 16 | |
| jah128 | 1:f6356cf1cefc | 17 | /// Use these variables to store the name for the program, the author and the version | 
| jah128 | 1:f6356cf1cefc | 18 | /// NB: Keep the strings as short as possible (ie 12 chars or less) to ensure reliable comms and readability on display | 
| jah128 | 0:8a5497a2e366 | 19 | char * program_name = "Example"; | 
| jah128 | 0:8a5497a2e366 | 20 | char * author_name = "JAH-YRL"; | 
| jah128 | 1:f6356cf1cefc | 21 | char * version_name = "1.0"; | 
| jah128 | 0:8a5497a2e366 | 22 | |
| jah128 | 0:8a5497a2e366 | 23 | // Place user variables here | 
| jah128 | 0:8a5497a2e366 | 24 | |
| jah128 | 0:8a5497a2e366 | 25 | char green = 3; | 
| jah128 | 0:8a5497a2e366 | 26 | char red = 48; | 
| jah128 | 0:8a5497a2e366 | 27 | int re =0 ; | 
| jah128 | 0:8a5497a2e366 | 28 | int le =0; | 
| jah128 | 0:8a5497a2e366 | 29 | |
| jah128 | 1:f6356cf1cefc | 30 | ///Place user code here that should be run after initialisation but before the main loop | 
| jah128 | 0:8a5497a2e366 | 31 | void user_code_setup(){ | 
| jah128 | 0:8a5497a2e366 | 32 | |
| jah128 | 0:8a5497a2e366 | 33 | /* | 
| jah128 | 0:8a5497a2e366 | 34 | wait(2); | 
| jah128 | 0:8a5497a2e366 | 35 | calibrate_base_ir_sensors(); | 
| jah128 | 0:8a5497a2e366 | 36 | wait(2); | 
| jah128 | 0:8a5497a2e366 | 37 | */ | 
| jah128 | 0:8a5497a2e366 | 38 | } | 
| jah128 | 0:8a5497a2e366 | 39 | |
| jah128 | 1:f6356cf1cefc | 40 | ///This function is the loop where user code should be placed | 
| jah128 | 1:f6356cf1cefc | 41 | void user_code_loop(){ | 
| jah128 | 1:f6356cf1cefc | 42 | ///Do not place code within a loop, but consider this function to be a loop that is always run | 
| jah128 | 1:f6356cf1cefc | 43 | ///unless the user code is externally paused (such as by debug or recharging system) | 
| jah128 | 0:8a5497a2e366 | 44 | |
| jah128 | 0:8a5497a2e366 | 45 | |
| jah128 | 0:8a5497a2e366 | 46 | } | 
| jah128 | 0:8a5497a2e366 | 47 | |
| jah128 | 0:8a5497a2e366 | 48 | |
| jah128 | 1:f6356cf1cefc | 49 | /// Code goes here to handle what should happen when the user switch is pressed | 
| jah128 | 0:8a5497a2e366 | 50 | void handle_switch_event(char switch_state) | 
| jah128 | 0:8a5497a2e366 | 51 | { | 
| jah128 | 1:f6356cf1cefc | 52 | /// Switch_state = 1 if up is pressed, 2 if down is pressed, 4 if left is pressed, 8 if right is pressed and 16 if the center button is pressed | 
| jah128 | 1:f6356cf1cefc | 53 | /// NB For maximum compatability it is recommended to minimise reliance on center button press | 
| jah128 | 0:8a5497a2e366 | 54 | } | 
| jah128 | 0:8a5497a2e366 | 55 | |
| jah128 | 1:f6356cf1cefc | 56 | /// The main routine: it is recommended to leave this function alone and add user code to the above functions | 
| jah128 | 0:8a5497a2e366 | 57 | int main() { | 
| jah128 | 1:f6356cf1cefc | 58 | ///init() in psiswarm.cpp sets up the robot | 
| jah128 | 0:8a5497a2e366 | 59 | init(); | 
| jah128 | 0:8a5497a2e366 | 60 | user_code_setup(); | 
| jah128 | 0:8a5497a2e366 | 61 | user_code_running = 1; | 
| jah128 | 0:8a5497a2e366 | 62 | while(1) { | 
| jah128 | 0:8a5497a2e366 | 63 | if(user_code_running)user_code_loop(); | 
| jah128 | 0:8a5497a2e366 | 64 | if(demo_on) demo_mode(); | 
| jah128 | 0:8a5497a2e366 | 65 | wait_us(250); | 
| jah128 | 0:8a5497a2e366 | 66 | } | 
| jah128 | 0:8a5497a2e366 | 67 | } | 
