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.
Robo.h
00001 #ifndef __ROBO_H 00002 #define __ROBO_H 00003 00004 #include "Motor.h" 00005 #include "mbed.h" 00006 #include "TextLCD.h" 00007 00008 // intial lives each robot has 00009 const int max_lives = 5; 00010 00011 /* for storing the motors' state, e.g. the robot is moving forward 00012 * and it receives a request to go left. After it has turned left 00013 * it must keep moving forward. So we use this structure to backup and restore 00014 * motors' state. 00015 */ 00016 struct rState { 00017 mState lm; // pin states of the left motor 00018 mState rm; // pin states of the right motor 00019 }; 00020 00021 /* main Robo Class definition 00022 */ 00023 class Robo { 00024 int lives; 00025 Motor lmotor; 00026 Motor rmotor; 00027 TextLCD lcd; 00028 public : 00029 Robo(PinName l_en, PinName l_fwd, PinName l_rev, // left motor's enable, forward, and reverse 00030 PinName r_en, PinName r_fwd, PinName r_rev, // right motor's enable, forward and reverse 00031 PinName rs, PinName en, PinName d4, PinName d5, // pins for LCD rs, en , d4-d7 00032 PinName d6, PinName d7); 00033 void init(); // for initialization of the robot 00034 void printlcd(char *); // print a message on the robot's lcd 00035 void updateLivesLCD(); // update the lives count 00036 void goLeft(); 00037 void moveRight(); 00038 void stop(); 00039 void goAhead(); 00040 void moveBack(); 00041 int getLives(); // get the number of lives left 00042 void decLives(); // decrease the number of lives 00043 rState getState(); // get the state of the robot 00044 void setState(rState); // set the state of the robot 00045 00046 }; 00047 00048 00049 00050 #endif
Generated on Tue Jul 19 2022 06:58:25 by
1.7.2