aa

Dependencies:   mbed-rtos mbed

Committer:
jfields
Date:
Fri Oct 16 17:17:41 2015 +0000
Revision:
0:cbf3d33db709
serv

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jfields 0:cbf3d33db709 1 #include "mbed.h"
jfields 0:cbf3d33db709 2 #include "rtos.h"
jfields 0:cbf3d33db709 3
jfields 0:cbf3d33db709 4 PwmOut servo1(p25);
jfields 0:cbf3d33db709 5 PwmOut servo2(p24);
jfields 0:cbf3d33db709 6
jfields 0:cbf3d33db709 7 // Threads
jfields 0:cbf3d33db709 8 void bpc_func(void const *args);
jfields 0:cbf3d33db709 9 Thread * bpc_thread;
jfields 0:cbf3d33db709 10
jfields 0:cbf3d33db709 11 float dty_servo_open = 0.1125; // PCT [3.75-11.25]
jfields 0:cbf3d33db709 12 float dty_servo_close = 0.0375; // PCT [3.75-11.25]
jfields 0:cbf3d33db709 13 float period = 0.02; // sec
jfields 0:cbf3d33db709 14
jfields 0:cbf3d33db709 15 AnalogIn Button(p15); // elevator button press Voltage = 3.3*0.2*n ; n = Floor Number
jfields 0:cbf3d33db709 16
jfields 0:cbf3d33db709 17
jfields 0:cbf3d33db709 18 int main() {
jfields 0:cbf3d33db709 19
jfields 0:cbf3d33db709 20 servo1.period(period);
jfields 0:cbf3d33db709 21 servo2.period(period);
jfields 0:cbf3d33db709 22 bpc_thread = new Thread(bpc_func); // start button checker thread
jfields 0:cbf3d33db709 23
jfields 0:cbf3d33db709 24
jfields 0:cbf3d33db709 25 while(1) {
jfields 0:cbf3d33db709 26
jfields 0:cbf3d33db709 27 }
jfields 0:cbf3d33db709 28 }
jfields 0:cbf3d33db709 29
jfields 0:cbf3d33db709 30 void bpc_func(void const *args) {
jfields 0:cbf3d33db709 31 while (1) {
jfields 0:cbf3d33db709 32 float ADC_val = Button.read();
jfields 0:cbf3d33db709 33 int val = ADC_val*10;
jfields 0:cbf3d33db709 34 if(val == 2) {
jfields 0:cbf3d33db709 35 // blah
jfields 0:cbf3d33db709 36 } else if(val == 4) {
jfields 0:cbf3d33db709 37 // blah
jfields 0:cbf3d33db709 38 } else if(val == 6) {
jfields 0:cbf3d33db709 39 // blah
jfields 0:cbf3d33db709 40 } else if(val == 8) {
jfields 0:cbf3d33db709 41 servo1.write(dty_servo_open);
jfields 0:cbf3d33db709 42 servo2.write(dty_servo_open);
jfields 0:cbf3d33db709 43 } else if(val == 10) {
jfields 0:cbf3d33db709 44 servo1.write(dty_servo_close);
jfields 0:cbf3d33db709 45 servo2.write(dty_servo_close);
jfields 0:cbf3d33db709 46 }
jfields 0:cbf3d33db709 47 wait(0.1);
jfields 0:cbf3d33db709 48 }
jfields 0:cbf3d33db709 49 }