~
Revision 1:cd5247f3a499, committed 2016-09-11
- Comitter:
- kswanson31
- Date:
- Sun Sep 11 22:24:03 2016 +0000
- Parent:
- 0:f58f38896cfa
- Child:
- 2:f131a1777c54
- Child:
- 3:30be02620bad
- Commit message:
- Changed LED and switch pins. Added code for extra credit, control with potentiometer
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Fri Sep 09 22:14:06 2016 +0000
+++ b/main.cpp Sun Sep 11 22:24:03 2016 +0000
@@ -3,18 +3,22 @@
#include "MCP23S17.h"
// 1
-DigitalIn dip_switch8(p21);
-DigitalOut green_led(p22);
+DigitalIn dip_switch3(p30);
+DigitalOut red_led(p17);
// 2
-DigitalIn dip_switch1(p26);
-DigitalIn dip_switch2(p25);
-PwmOut blue_led(p23);
+DigitalIn dip_switch1(p28);
+DigitalIn dip_switch2(p29);
+PwmOut green_led(p21);
// 3
SPI spi(p5, p6, p7); // SPI bus
char Opcode = 0x40; // 8-bit address for writes
MCP23S17 chip = MCP23S17(spi, p20, Opcode); // create an MCP23S17
-
int switch_state;
+// Analog control
+AnalogIn control_pot(p18);
+PwmOut rgb_b(p22);
+PwmOut rgb_r(p23);
+PwmOut rgb_g(p24);
int main()
{
@@ -22,8 +26,8 @@
dip_switch1.mode(PullUp); // configure internal pull up resistor
dip_switch2.mode(PullUp);
- blue_led.period(0.016f); // ~ 60 Hz
- blue_led.write(0.50f); // 50 % duty cycle
+ green_led.period(0.016f); // ~ 60 Hz
+ green_led.write(0.50f); // 50 % duty cycle
// 3
chip.direction(PORT_A, 0x00); // set all Port A bits to output
@@ -32,16 +36,16 @@
while(1) {
// 1
- green_led = dip_switch8;
+ red_led = dip_switch3;
// 2
if (!dip_switch1) {
- blue_led.write(0.25f); // half start brightness, half duty cycle
+ green_led.write(0.25f); // half start brightness, half duty cycle
}
else if (!dip_switch2) {
- blue_led.write(0.125f); // 1/4 starting brightness
+ green_led.write(0.125f); // 1/4 starting brightness
} else {
- blue_led.write(0.50f); // initial
+ green_led.write(0.50f); // initial
}
// 3
@@ -51,5 +55,10 @@
chip.write(PORT_A, switch_state);
wait(.2);
// yellow led should change opposite the green led
+
+ // Analog control
+ rgb_r = control_pot;
+ rgb_g = 0.5f - control_pot;
+ rgb_b = 1.0f - control_pot;
}
}