Lab 4ES_ColourMixer John Curran T00214119

Dependencies:   mbed

Committer:
johnc89
Date:
Mon Apr 19 18:19:19 2021 +0000
Revision:
3:3230439ce904
Parent:
2:7e2fbb1f16d4
Lab 4 Final Piece of code John Curran T00214119

Who changed what in which revision?

UserRevisionLine numberNew contents of line
johnc89 0:fb5ea244d4f6 1 // Lab 4 Colour Mixer
johnc89 2:7e2fbb1f16d4 2 // Control colours coming on using PWM Out interface using pot 1 and print values to tera term
johnc89 0:fb5ea244d4f6 3 // John Curran T00214119
johnc89 2:7e2fbb1f16d4 4 // when ADC data is between 0.0 and <= 0.2 all leds off
johnc89 2:7e2fbb1f16d4 5 // when ADC data is between 0.2 and <= 0.4 red led is on
johnc89 3:3230439ce904 6 // when ADC data is between 0.4 and <= 0.6 green led is on
johnc89 3:3230439ce904 7 // when ADC data is between 0.6 and <= 0.8 blue led is on
johnc89 3:3230439ce904 8 // when ADC data is between 0.8 and <= 1.0 yellow led is on
johnc89 0:fb5ea244d4f6 9 #include "mbed.h"
johnc89 0:fb5ea244d4f6 10 Serial pc(USBTX,USBRX);// serial communications
johnc89 0:fb5ea244d4f6 11 DigitalOut redled(p23);// built in red led
johnc89 0:fb5ea244d4f6 12 DigitalOut greenled(p24);// built in green led
johnc89 0:fb5ea244d4f6 13 DigitalOut blueled(p25);// built in blue led
johnc89 0:fb5ea244d4f6 14 AnalogIn Ain (p19); // Pot 1 control lights
johnc89 0:fb5ea244d4f6 15 float ADCdata; // Reserve a space in memory
johnc89 0:fb5ea244d4f6 16
johnc89 0:fb5ea244d4f6 17 int main ()
johnc89 0:fb5ea244d4f6 18 {
johnc89 0:fb5ea244d4f6 19 while (1) {
johnc89 0:fb5ea244d4f6 20 ADCdata=Ain;//read pin 19
johnc89 0:fb5ea244d4f6 21
johnc89 0:fb5ea244d4f6 22 if(ADCdata>0.0 && ADCdata <= 0.2) {
johnc89 2:7e2fbb1f16d4 23 pc.printf ( " ADCdata >0.0-<=0.2, All Leds Off\n\r");
johnc89 0:fb5ea244d4f6 24 redled = 1;
johnc89 0:fb5ea244d4f6 25 greenled=1;
johnc89 0:fb5ea244d4f6 26 blueled= 1;
johnc89 2:7e2fbb1f16d4 27 wait (0.5);
johnc89 1:03835eef0976 28 }
johnc89 0:fb5ea244d4f6 29
johnc89 1:03835eef0976 30
johnc89 0:fb5ea244d4f6 31 if(ADCdata>0.2 && ADCdata <= 0.4) {
johnc89 2:7e2fbb1f16d4 32 pc.printf ( " ADCdata >0.2-<=0.4, Red Led is on\n\r");
johnc89 0:fb5ea244d4f6 33 redled = 0;
johnc89 0:fb5ea244d4f6 34 greenled=1;
johnc89 0:fb5ea244d4f6 35 blueled= 1;
johnc89 2:7e2fbb1f16d4 36 wait(0.5);
johnc89 0:fb5ea244d4f6 37
johnc89 0:fb5ea244d4f6 38 }
johnc89 2:7e2fbb1f16d4 39 if(ADCdata>0.4 && ADCdata <= 0.6) {
johnc89 3:3230439ce904 40 pc.printf ( " ADCdata >0.4-<=0.6, Green Led is on\n\r");
johnc89 0:fb5ea244d4f6 41 redled = 1;
johnc89 0:fb5ea244d4f6 42 greenled=0;
johnc89 0:fb5ea244d4f6 43 blueled= 1;
johnc89 2:7e2fbb1f16d4 44 wait(0.5);
johnc89 0:fb5ea244d4f6 45
johnc89 0:fb5ea244d4f6 46 }
johnc89 2:7e2fbb1f16d4 47 if(ADCdata>0.6 && ADCdata <= 0.8) {
johnc89 3:3230439ce904 48 pc.printf ( " ADCdata >0.6-<=0.8, Blue Led is on\n\r");
johnc89 0:fb5ea244d4f6 49 redled = 1;
johnc89 0:fb5ea244d4f6 50 greenled=1;
johnc89 0:fb5ea244d4f6 51 blueled= 0;
johnc89 2:7e2fbb1f16d4 52 wait(0.5);
johnc89 0:fb5ea244d4f6 53
johnc89 0:fb5ea244d4f6 54 }
johnc89 2:7e2fbb1f16d4 55 if(ADCdata>0.8 && ADCdata <= 1.0) {
johnc89 3:3230439ce904 56 pc.printf ( " ADCdata >0.8-<=1.0, Yellow Led is on\n\r");
johnc89 0:fb5ea244d4f6 57 redled = 0;
johnc89 0:fb5ea244d4f6 58 greenled=0;
johnc89 0:fb5ea244d4f6 59 blueled= 1;
johnc89 2:7e2fbb1f16d4 60 wait(0.5);
johnc89 0:fb5ea244d4f6 61
johnc89 0:fb5ea244d4f6 62 }
johnc89 0:fb5ea244d4f6 63 }
johnc89 0:fb5ea244d4f6 64 }