4180 lab 1
Dependencies: mbed MCP23S17 PinDetect USBDevice
main.cpp
- Committer:
- emilywilson
- Date:
- 2020-01-15
- Revision:
- 4:6a7029bf4e1c
- Parent:
- 3:d84f4a501915
- Child:
- 5:d1ad3a964858
File content as of revision 4:6a7029bf4e1c:
#include "mbed.h" #include "RGBLed.h" #include "PinDetect.h" DigitalOut myled(p26); PwmOut builtinLED(LED1); DigitalIn pb(p22); //DigitalIn pb2(p21); // p10 is most significant bit BusIn ledSelect(p18, p19, p20); PinName redPin = p24; PinName greenPin = p25; PinName bluePin = p23; PinDetect pb1(p21); PinDetect pb2(p22); float volatile p = 1.0f; void pb1_hit_callback() { if (p > 0) { p -= 0.1; } } void pb2_hit_callback() { if (p < 0) { p += 0.1; } } int main() { pb1.mode(PullUp); pb2.mode(PullUp); wait(0.1); pb1.attach_asserted(&pb1_hit_callback); pb2.attach_asserted(&pb2_hit_callback); pb1.setSampleFrequency(); pb2.setSampleFrequency(); while(1) { // Part 1 // myled = !pb; // Part 2 // builtinLED = p; // wait(0.5); // Part 3 RGBLed myRBGLed = RGBLed(redPin, greenPin, bluePin); float redVal = 0.0f; float greenVal = 0.0f; float blueVal = 0.0f; if (ledSelect & 0x1) { redVal = 1.0 * p; } if (ledSelect & 0x2) { greenVal = 1.0 * p; } if (ledSelect & 0x4) { blueVal = 1.0 * p; } // Part 4 } }