4180Lab1Part1&2

Dependencies:   mbed

main.cpp

Committer:
CRaslawski
Date:
2017-01-24
Revision:
1:dcefd568845d
Parent:
0:3c5cdcee59dd
Child:
2:51a94a489f09

File content as of revision 1:dcefd568845d:

#include "mbed.h"

DigitalOut myled(LED1);
DigitalOut myled2(p25);
PwmOut myled3(p21);
DigitalIn pb(p24);
DigitalIn pwmup(p22);
DigitalIn pwmdown(p23);

int main() {
    // Part 1
    pb.mode(PullUp); // The variable left_pb will be zero when the pushbutton for moving the player left is pressed
    pwmup.mode(PullUp);
    pwmdown.mode(PullUp);
    
    // Part 2
    myled3.period(1.0f);
    volatile float duty = 0.50f;
    myled3.write(duty);
    while(1) {
        // Part 1
        while(pb == 0) {
            myled = 1;
            myled2 = 0;
        }
        myled = 0;
        myled2 = 1;
        
        // Part 2
        if(pwmup == 0 && duty < 1.00f) {
            duty = duty + 0.001f;
            //duty += 0.10f;
            //duty = 1.0f;
            myled3.write(duty);
        }
        if(pwmdown == 0 && duty > 0.00f) {
            duty = duty - 0.001f;
            //duty -= 0.10f;
            //duty = 0.0f;
            myled3.write(duty);
        }
    }
}