Allows you to control LED flash speed and brightness by using the analog slider switch & the potentiometer. furthermore, the 4 push buttons each have their own flash patterns.

Dependencies:   mbed tsi_sensor

Committer:
s_booth9
Date:
Mon Feb 23 03:52:53 2015 +0000
Revision:
1:d346428e30a2
Parent:
0:2cf594207c1a
revision of previous light show code, now with added header and use of else if statements instead of simply if statements.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
s_booth9 1:d346428e30a2 1 //Program: light show Booth
s_booth9 1:d346428e30a2 2 //Author: Spencer Booth
s_booth9 1:d346428e30a2 3 //Date: 22 Feb 2015
s_booth9 1:d346428e30a2 4 //Description: this program will allow the user to change the LED
s_booth9 1:d346428e30a2 5 // flash pattern as well as flash speed and brightness.
s_booth9 1:d346428e30a2 6
s_booth9 0:2cf594207c1a 7 //preproccesor statements
s_booth9 0:2cf594207c1a 8 #include "mbed.h"
s_booth9 0:2cf594207c1a 9 #include "tsi_sensor.h"
s_booth9 0:2cf594207c1a 10
s_booth9 0:2cf594207c1a 11 //setting my inputs for the switches and slider
s_booth9 0:2cf594207c1a 12 DigitalIn Switch1(PTD5); // push button switches on the protoboard
s_booth9 0:2cf594207c1a 13 DigitalIn Switch2(PTA13);
s_booth9 0:2cf594207c1a 14 DigitalIn Switch3(PTC9);
s_booth9 0:2cf594207c1a 15 DigitalIn Switch4(PTC8);
s_booth9 0:2cf594207c1a 16
s_booth9 0:2cf594207c1a 17 PwmOut ProtoBoardRed(PTA4); // protoboard LED outputs
s_booth9 0:2cf594207c1a 18 PwmOut ProtoBoardGreen(PTD4);
s_booth9 0:2cf594207c1a 19 PwmOut ProtoBoardYellow(PTA12);
s_booth9 0:2cf594207c1a 20
s_booth9 0:2cf594207c1a 21 PwmOut Green(LED_GREEN); // PWM outputs tied to MBED LEDs
s_booth9 0:2cf594207c1a 22 PwmOut Red(LED_RED);
s_booth9 0:2cf594207c1a 23 PwmOut Blue(LED_BLUE);
s_booth9 1:d346428e30a2 24 AnalogIn Potentiometer(A0); // LED brightness controller
s_booth9 0:2cf594207c1a 25
s_booth9 1:d346428e30a2 26 TSIAnalogSlider tsi(PTB16,PTB17,50);// LED flash speed controller
s_booth9 0:2cf594207c1a 27
s_booth9 0:2cf594207c1a 28 int main()
s_booth9 0:2cf594207c1a 29 {
s_booth9 0:2cf594207c1a 30 while(1)
s_booth9 0:2cf594207c1a 31 {
s_booth9 1:d346428e30a2 32 if(Switch1 == 0) // flash pattern for when switch 1 is pressed
s_booth9 0:2cf594207c1a 33 {
s_booth9 0:2cf594207c1a 34 ProtoBoardRed = Potentiometer;
s_booth9 0:2cf594207c1a 35 ProtoBoardGreen = Potentiometer;
s_booth9 0:2cf594207c1a 36 ProtoBoardYellow = Potentiometer;
s_booth9 0:2cf594207c1a 37 wait(1 - tsi.readPercentage() );
s_booth9 0:2cf594207c1a 38
s_booth9 0:2cf594207c1a 39 ProtoBoardRed = 0;
s_booth9 0:2cf594207c1a 40 ProtoBoardGreen = 0;
s_booth9 0:2cf594207c1a 41 ProtoBoardYellow = 0;
s_booth9 0:2cf594207c1a 42 wait(1 - tsi.readPercentage() );
s_booth9 0:2cf594207c1a 43 }
s_booth9 1:d346428e30a2 44 else if(Switch2 == 0) // flash pattern for when switch 2 is pressed
s_booth9 0:2cf594207c1a 45 {
s_booth9 0:2cf594207c1a 46 ProtoBoardRed = Potentiometer;
s_booth9 0:2cf594207c1a 47 ProtoBoardGreen = Potentiometer;
s_booth9 0:2cf594207c1a 48 ProtoBoardYellow = 0;
s_booth9 0:2cf594207c1a 49 wait(1 - tsi.readPercentage() );
s_booth9 0:2cf594207c1a 50
s_booth9 0:2cf594207c1a 51 ProtoBoardRed = 0;
s_booth9 0:2cf594207c1a 52 ProtoBoardGreen = 0;
s_booth9 0:2cf594207c1a 53 ProtoBoardYellow = Potentiometer;
s_booth9 0:2cf594207c1a 54 wait(1 - tsi.readPercentage() );
s_booth9 0:2cf594207c1a 55 }
s_booth9 1:d346428e30a2 56 else if(Switch3 == 0)// flash pattern for when switch 3 is pressed
s_booth9 0:2cf594207c1a 57 {
s_booth9 0:2cf594207c1a 58 ProtoBoardRed = Potentiometer;
s_booth9 0:2cf594207c1a 59 ProtoBoardGreen = 0;
s_booth9 0:2cf594207c1a 60 ProtoBoardYellow = 0;
s_booth9 0:2cf594207c1a 61 wait(1 - tsi.readPercentage() );
s_booth9 0:2cf594207c1a 62
s_booth9 0:2cf594207c1a 63 ProtoBoardRed = 0;
s_booth9 0:2cf594207c1a 64 ProtoBoardGreen = Potentiometer;
s_booth9 0:2cf594207c1a 65 ProtoBoardYellow = 0;
s_booth9 0:2cf594207c1a 66 wait(1 - tsi.readPercentage() );
s_booth9 0:2cf594207c1a 67
s_booth9 0:2cf594207c1a 68 ProtoBoardRed = 0;
s_booth9 0:2cf594207c1a 69 ProtoBoardGreen = 0;
s_booth9 0:2cf594207c1a 70 ProtoBoardYellow = Potentiometer;
s_booth9 0:2cf594207c1a 71 wait(1 - tsi.readPercentage() );
s_booth9 0:2cf594207c1a 72 }
s_booth9 1:d346428e30a2 73 else if(Switch4 == 0)// flash pattern for when switch 4 is pressed(combination of the last 3 switches patterns)
s_booth9 0:2cf594207c1a 74 {
s_booth9 0:2cf594207c1a 75 Red = 1;
s_booth9 0:2cf594207c1a 76
s_booth9 0:2cf594207c1a 77 ProtoBoardRed = Potentiometer;
s_booth9 0:2cf594207c1a 78 ProtoBoardGreen = Potentiometer;
s_booth9 0:2cf594207c1a 79 ProtoBoardYellow = Potentiometer;
s_booth9 0:2cf594207c1a 80 wait(1 - tsi.readPercentage() );
s_booth9 0:2cf594207c1a 81 Red = 0;
s_booth9 0:2cf594207c1a 82
s_booth9 0:2cf594207c1a 83 ProtoBoardRed = 0;
s_booth9 0:2cf594207c1a 84 ProtoBoardGreen = 0;
s_booth9 0:2cf594207c1a 85 ProtoBoardYellow = 0;
s_booth9 0:2cf594207c1a 86 wait(1 - tsi.readPercentage() );
s_booth9 0:2cf594207c1a 87 Blue = 1;
s_booth9 0:2cf594207c1a 88
s_booth9 0:2cf594207c1a 89 ProtoBoardRed = Potentiometer;
s_booth9 0:2cf594207c1a 90 ProtoBoardGreen = Potentiometer;
s_booth9 0:2cf594207c1a 91 ProtoBoardYellow = 0;
s_booth9 0:2cf594207c1a 92 wait(1 - tsi.readPercentage() );
s_booth9 0:2cf594207c1a 93 Blue = 0;
s_booth9 0:2cf594207c1a 94
s_booth9 0:2cf594207c1a 95 ProtoBoardRed = 0;
s_booth9 0:2cf594207c1a 96 ProtoBoardGreen = 0;
s_booth9 0:2cf594207c1a 97 ProtoBoardYellow = Potentiometer;
s_booth9 0:2cf594207c1a 98 wait(1 - tsi.readPercentage() );
s_booth9 0:2cf594207c1a 99 Green = 1;
s_booth9 0:2cf594207c1a 100
s_booth9 0:2cf594207c1a 101 ProtoBoardRed = Potentiometer;
s_booth9 0:2cf594207c1a 102 ProtoBoardGreen = 0;
s_booth9 0:2cf594207c1a 103 ProtoBoardYellow = 0;
s_booth9 0:2cf594207c1a 104 wait(1 - tsi.readPercentage() );
s_booth9 0:2cf594207c1a 105 Green = 0;
s_booth9 0:2cf594207c1a 106
s_booth9 0:2cf594207c1a 107 ProtoBoardRed = 0;
s_booth9 0:2cf594207c1a 108 ProtoBoardGreen = Potentiometer;
s_booth9 0:2cf594207c1a 109 ProtoBoardYellow = 0;
s_booth9 0:2cf594207c1a 110 wait(1 - tsi.readPercentage() );
s_booth9 0:2cf594207c1a 111 Red = 1;
s_booth9 0:2cf594207c1a 112 Blue = 1;
s_booth9 0:2cf594207c1a 113 Green = 1;
s_booth9 0:2cf594207c1a 114
s_booth9 0:2cf594207c1a 115 ProtoBoardRed = 0;
s_booth9 0:2cf594207c1a 116 ProtoBoardGreen = 0;
s_booth9 0:2cf594207c1a 117 ProtoBoardYellow = Potentiometer;
s_booth9 0:2cf594207c1a 118 wait(1 - tsi.readPercentage() );
s_booth9 0:2cf594207c1a 119 Red = 0;
s_booth9 0:2cf594207c1a 120 Blue = 0;
s_booth9 0:2cf594207c1a 121 Green = 0;
s_booth9 0:2cf594207c1a 122 }
s_booth9 1:d346428e30a2 123 else // if no button is pressed, no lights will be on.
s_booth9 0:2cf594207c1a 124 {
s_booth9 0:2cf594207c1a 125 ProtoBoardRed = 0;
s_booth9 0:2cf594207c1a 126 ProtoBoardGreen = 0;
s_booth9 0:2cf594207c1a 127 ProtoBoardYellow = 0;
s_booth9 0:2cf594207c1a 128 Red = 0;
s_booth9 0:2cf594207c1a 129 Blue = 0;
s_booth9 0:2cf594207c1a 130 Green = 0;
s_booth9 0:2cf594207c1a 131 }
s_booth9 0:2cf594207c1a 132 }
s_booth9 0:2cf594207c1a 133 }