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.
Revision 4:3588eff6d065, committed 2014-03-12
- Comitter:
- dbearg
- Date:
- Wed Mar 12 21:38:21 2014 +0000
- Parent:
- 3:59a9bd160e29
- Commit message:
- added section for code help.; added button lockout to protect motor and gears.
Changed in this revision
| code_help.cpp | Show annotated file Show diff for this revision Revisions of this file |
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/code_help.cpp Wed Mar 12 21:38:21 2014 +0000
@@ -0,0 +1,134 @@
+//%%=================================%%
+//%% FLOWCHART TO CODE CONVERSION %%
+//%%=================================%%
+//
+// DECISION BOX
+// --------------
+//
+//
+// ____
+// / A=B \__TRUE____>
+// \_____/
+// |______FALSE
+//
+// CODE
+// --------
+//
+// a equals b
+//
+// if(a == b){
+// ;
+// ;
+// }
+//
+// a less than or = to b
+//
+// if(a <= b){
+// ;
+// ;
+// }
+//
+//=======================================
+//
+// INPUTS
+// --------
+// ____
+// |____|
+// |
+// V
+// CODE
+// --------
+// type name(pin);
+//
+// TYPES:
+// DigitalIn
+// AnalogIn
+//
+// EXAMPLES:
+// DigitalIn enable(p30);
+// AnalogIn ain(p19);
+//
+//
+//
+//==========================================
+//
+// VARIABLES
+// -----------
+// ____
+// |____|
+// |
+// V
+// CODE
+// --------
+//
+// type variable = value;
+// types:
+// int.........integer (whole numbers, 1, 4, 128, etc)
+// float.......floating point decimal (0.1, 3.62783, etc)
+//
+// NOTE: value has to match data type.
+// see website http://mbed.org/handbook/C-Data-Types for more information
+//
+//
+//===========================================
+//
+//
+// COUNTER LOOP EXAMPLE
+// ----------------------
+// ____________
+// | |
+// | MOTOR |
+// | SPEED = A |
+// |____________|
+// | ___________________________________
+// ______V____________ | |
+// | | | SOME INCREMENTED ACTION, EXAMPLE: |
+// | IF COUNT = X THEN |<_______| MOTOR SPEED IS MOTOR SPEED + A |
+// | BREAK THE LOOP | |___________________________________|
+// |___________________| ^
+// | | ___________ |
+// | | | | |
+// | |_________>| COUNT + 1 |_____________|
+// V |___________|
+//
+// CODE
+// ------
+//
+// for(int count = 0; count <10; count = count + 1){
+// ;
+// ;
+// }
+//
+//
+//
+//============================================
+//
+//
+// CONTINUOUS LOOP EXAMPLE
+// -------------------------
+//
+// _______________
+// | |
+// | START OF LOOP |
+// |_______________|
+// |
+// |<---------------
+// | |
+// ________V________ |
+// | | |
+// | LOGIC STATEMENT | |
+// |_________________| |
+// | |
+// ________V________ |
+// | | |
+// | LOGIC STATEMENT |_______|
+// |_________________|
+//
+// CODE
+// ------
+//
+// while(1) {
+// ;
+// ;
+// }
+//
--- a/main.cpp Sat Feb 01 18:26:06 2014 +0000
+++ b/main.cpp Wed Mar 12 21:38:21 2014 +0000
@@ -1,17 +1,18 @@
-//==================================
-//
-// PLTW PROGRAM
-// ----------------------------
-// Controls a PWM output using
-// digital inputs
-//
-// SPEEDS:
-// 0.00 - 0.49 reverse
-// 0.49 - 0.51 zero
-// 0.51 - 1.00 forward
-
-//==================================
-
+//=======================================|
+//%|==================================|%%|
+//%| |%%|
+//%| PLTW PROGRAM |%%|
+//%| ---------------------------- |%%|
+//%| Controls a PWM output using |%%|
+//%| digital inputs |%%|
+//%| |%%|
+//%| MOTOR SPEED: |%%|
+//%| 0.00 - 0.49 reverse |%%|
+//%| 0.49 - 0.51 zero |%%|
+//%| 0.51 - 1.00 forward |%%|
+//%| |%%|
+//%|==================================|%%|
+//=======================================|
//==================================
// Add any libraries that you use:
@@ -37,6 +38,9 @@
//add variables for button inputs on pins 15, 16, 17, and 18.
InterruptIn a(p18), b(p17), c(p16), d(p15);
+//add variable for button press //=========================================== NEW
+int apress = 0; //=========================================== NEW
+
//==================================
// Functions for each button press
//==================================
@@ -45,23 +49,33 @@
// Functions for button 1
void a_hit_interrupt (void) {
- //move VEX motor (1 is full CCW, 0 is full CW)
- speed = 1.0;
- motor1 = speed;
- //set the motor on duration in seconds:
- wait(1);
- //stop motor
- speed = 0.5;
- motor1 = speed;
+ if(apress == 0){ // PRESSING A WILL DO NOTHING AFTER THE FIRST PRESS
+ // UNLESS THE B BUTTON HAS BEEN PRESSED
+ //set the apress variable to 1 // SET APRESS VARIABLE TO 1
+ apress = 1; // SET APRESS VARIABLE TO 1
+
+ //move VEX motor (1 is full CCW, 0 is full CW)
+ speed = 1.0;
+ motor1 = speed;
+ //set the motor on duration in seconds:
+ wait(1);
+ //stop motor
+ speed = 0.5;
+ motor1 = speed;
- //Set LED 1
- led1 = 1, led2 = 0, led3 = 0, led4 = 0;
+ //Set LED 1
+ led1 = 1, led2 = 0, led3 = 0, led4 = 0;
+ }
}
// Functions for button 2
void b_hit_interrupt (void) {
+ if(apress == 1){ // PRESSING B WILL DO NOTHING IF A HAS NOT PRESSED
+
+ //set the apress variable to 1 // RESET APRESS VARIABLE TO 0
+ apress = 0; // RESET APRESS VARIABLE TO 0
//move VEX motor (1 is full CCW, 0 is full CW)
speed = 0.0;
@@ -74,6 +88,7 @@
//Set LED 2
led1 = 0, led2 = 1, led3 = 0, led4 = 0;
+ }
}