Pass Computer IIB

Code

18 Sep 2019
  1. include "mbed.h"

PwmOut DCPwm(PB_7); PWM output for Lane Closer DigitalOut DCFwd(PA_5); FWD dir control DigitalOut DCRev(PA_4); REV dir control PwmOut Servo(PA_0); PWM output for Boom Gate

DigitalIn SW0(PB_12); SW0 pin for Boom Gate Entrance sensor DigitalIn SW1(PB_13); SW1 pin for Boom Gate Exit sensor DigitalIn SW7(PC_12); SW7 pin for Lane Closer sensor DigitalIn SW6(PC_9); SW6 pin for Height sensor

int main() { int truckFlag = 0;

DCPwm.period(0.01); DC Motor PWM Freq =100Hz (10mS) Servo.period(0.02); Servo PWM Freq = 50Hz (20mS)

Servo.pulsewidth_us(1472); default position is 90'

while(1) { control the boom gate if((SW0 == 0) && (SW1 == 1)) { Servo.pulsewidth_us(2400); turn to 180' } else if((SW0 == 1) && (SW1 == 0)) { Servo.pulsewidth_us(1472); turn to 90' }

control the lane closer if(SW7 == 0) { while(SW7 == 0) { if(SW6 == 0) truckFlag = 1; else truckFlag = 0; }

if(truckFlag == 1) { DCPwm = 1.0; 100% speed DCFwd = 1; turn motor CW DCRev = 0; wait(2.0); turn for 2sec DCFwd = 1; stop motor DCRev = 1; wait(6.0); wait for 6sec DCPwm = 0.5; 50% speed DCFwd = 0; turn motor CCW DCRev = 1; wait(4.0); turn for 4sec DCFwd = 1; stop motor DCRev = 1; } } } }