4180 lab 1
Dependencies: mbed MCP23S17 PinDetect USBDevice
Diff: main.cpp
- Revision:
- 0:c1654e25cc43
- Child:
- 1:f121b88d9c85
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Wed Jan 15 18:13:43 2020 +0000 @@ -0,0 +1,84 @@ +#include "mbed.h" +#include "RGBLed.h" +#include "PinDetect.h" + +DigitalOut myled(p26); +DigitalIn pb(p22); +DigitalIn pb2(p21); + +// p10 is most significant bit +//BusIn ledSelect(p8, p9, p10); +// +//PinName redPin = p11; +//PinName greenPin = p12; +//PinName bluePin = p13; +// +PinDetect pb1(p8); +PinDetect pb2(p9); + +float volatile p; + +void pb1_hit_callback() { + if (p > 0) { + p -= 0.1; + } +} + +void pb2_hit_callback() { + if (p < 0) { + p += 0.1; + } +} + +int main() { + while(1) { + // Part 1 + myled = !pb; + + // Part 2 + float p = 1.0f; + pb1.mode(PullUp); + pb2.mode(PullUp); + wait(0.1) + + if (pb1) { + if (p > 0) { + p -= 0.1; + } + } else if (pb2) { + if (p < 1) { + p += 0.1; + } + } + myled = p; + + // Part 3 +// RGBLed myRBGLed = RGBLed(redPin, greenPin, bluePin); +// float redVal = 0.0f; +// float greenVal = 0.0f; +// float blueVal = 0.0f; +// +// pb1.mode(PullUp) +// pb2.mode(PullUp) +// wait(0.1) +// +// // Possibly try attach_asserted +// pb1.attach_deasserted(&pb1_hit_callback); +// pb2.attach_deasserted(&pb2_hit_callback); +// pb1.setSampleFrequency(); +// pb2.setSampleFrequency(); +// +// if (ledSelect & 0x1) { +// redVal = 1.0 * p; +// } +// if (ledSelect & 0x2) { +// greenVal = 1.0 * p; +// } +// if (ledselect & 0x4) { +// blueVal = 1.0 * p; +// } +// } + + // Part 4 + +}