4180 lab 1
Dependencies: mbed MCP23S17 PinDetect USBDevice
main.cpp
- Committer:
- emilywilson
- Date:
- 2020-01-15
- Revision:
- 2:7570a8526148
- Parent:
- 1:f121b88d9c85
- Child:
- 3:d84f4a501915
File content as of revision 2:7570a8526148:
#include "mbed.h" #include "RGBLed.h" #include "PinDetect.h" DigitalOut myled(p26); DigitalOut builtinLED(LED1); 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(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() { 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; } } builtinLED = 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 } }