4180Lab1Part1&2

Dependencies:   mbed

Committer:
CRaslawski
Date:
Tue Jan 24 23:51:32 2017 +0000
Revision:
1:dcefd568845d
Parent:
0:3c5cdcee59dd
Child:
2:51a94a489f09
increase pwm frequency

Who changed what in which revision?

UserRevisionLine numberNew contents of line
CRaslawski 0:3c5cdcee59dd 1 #include "mbed.h"
CRaslawski 0:3c5cdcee59dd 2
CRaslawski 0:3c5cdcee59dd 3 DigitalOut myled(LED1);
CRaslawski 0:3c5cdcee59dd 4 DigitalOut myled2(p25);
CRaslawski 0:3c5cdcee59dd 5 PwmOut myled3(p21);
CRaslawski 0:3c5cdcee59dd 6 DigitalIn pb(p24);
CRaslawski 0:3c5cdcee59dd 7 DigitalIn pwmup(p22);
CRaslawski 0:3c5cdcee59dd 8 DigitalIn pwmdown(p23);
CRaslawski 0:3c5cdcee59dd 9
CRaslawski 0:3c5cdcee59dd 10 int main() {
CRaslawski 0:3c5cdcee59dd 11 // Part 1
CRaslawski 0:3c5cdcee59dd 12 pb.mode(PullUp); // The variable left_pb will be zero when the pushbutton for moving the player left is pressed
CRaslawski 0:3c5cdcee59dd 13 pwmup.mode(PullUp);
CRaslawski 0:3c5cdcee59dd 14 pwmdown.mode(PullUp);
CRaslawski 0:3c5cdcee59dd 15
CRaslawski 0:3c5cdcee59dd 16 // Part 2
CRaslawski 1:dcefd568845d 17 myled3.period(1.0f);
CRaslawski 0:3c5cdcee59dd 18 volatile float duty = 0.50f;
CRaslawski 0:3c5cdcee59dd 19 myled3.write(duty);
CRaslawski 0:3c5cdcee59dd 20 while(1) {
CRaslawski 0:3c5cdcee59dd 21 // Part 1
CRaslawski 0:3c5cdcee59dd 22 while(pb == 0) {
CRaslawski 0:3c5cdcee59dd 23 myled = 1;
CRaslawski 0:3c5cdcee59dd 24 myled2 = 0;
CRaslawski 0:3c5cdcee59dd 25 }
CRaslawski 0:3c5cdcee59dd 26 myled = 0;
CRaslawski 0:3c5cdcee59dd 27 myled2 = 1;
CRaslawski 0:3c5cdcee59dd 28
CRaslawski 0:3c5cdcee59dd 29 // Part 2
CRaslawski 0:3c5cdcee59dd 30 if(pwmup == 0 && duty < 1.00f) {
CRaslawski 1:dcefd568845d 31 duty = duty + 0.001f;
CRaslawski 0:3c5cdcee59dd 32 //duty += 0.10f;
CRaslawski 0:3c5cdcee59dd 33 //duty = 1.0f;
CRaslawski 0:3c5cdcee59dd 34 myled3.write(duty);
CRaslawski 0:3c5cdcee59dd 35 }
CRaslawski 0:3c5cdcee59dd 36 if(pwmdown == 0 && duty > 0.00f) {
CRaslawski 1:dcefd568845d 37 duty = duty - 0.001f;
CRaslawski 0:3c5cdcee59dd 38 //duty -= 0.10f;
CRaslawski 0:3c5cdcee59dd 39 //duty = 0.0f;
CRaslawski 0:3c5cdcee59dd 40 myled3.write(duty);
CRaslawski 0:3c5cdcee59dd 41 }
CRaslawski 0:3c5cdcee59dd 42 }
CRaslawski 0:3c5cdcee59dd 43 }