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: mbed
Diff: main.cpp
- Revision:
- 3:66a52943c525
- Parent:
- 2:bf817b299c19
- Child:
- 4:acb62dee5ba9
diff -r bf817b299c19 -r 66a52943c525 main.cpp
--- a/main.cpp Thu Oct 08 23:06:45 2015 +0000
+++ b/main.cpp Fri Oct 09 00:56:25 2015 +0000
@@ -13,10 +13,14 @@
DigitalOut dc2(p6); //DC motor input-2
PwmOut pwm3(p23); //DC motor PWM channel
+AnalogIn button(p15); //Analog input from the floor buttons
+
Serial pc(USBTX, USBRX);
void openGate();
void closeGate();
+int getState(float adc_val);
+
int currentState = 1;
int main() {
@@ -33,8 +37,12 @@
pwm2.write(0);
while(1){
- char c = pc.getc();
- int val = c - 48;
+ //char c = pc.getc();
+ //int val = c - 48;
+ float adc_val = button.read();
+ int val = getState(adc_val);
+ //pc.printf("Floor-%d\n",val);
+ //wait(1);
if(val==currentState){
pwm3.write(0);
}
@@ -54,8 +62,8 @@
pwm3.write(0);
}
currentState = val;
- openGate();
- closeGate();
+ //openGate();
+ //closeGate();
}
}
@@ -75,4 +83,24 @@
pwm1.write(0); // Stop
pwm2.write(0); // Stop
wait(2);
+}
+
+int getState(float adc_val){
+ int state = 0;
+ if(adc_val > 0.15 && adc_val < 0.25){
+ state = 1;
+ }
+ else if(adc_val > 0.35 && adc_val < 0.45){
+ state = 2;
+ }
+ else if(adc_val > 0.55 && adc_val < 0.65){
+ state = 3;
+ }
+ else if(adc_val > 0.75 && adc_val < 0.85){
+ state = 4;
+ }
+ else if(adc_val > 0.95 && adc_val < 1.05){
+ state = 5;
+ }
+ return state;
}
\ No newline at end of file