Lab 4ES_ColourMixer John Curran T00214119

Dependencies:   mbed

Committer:
johnc89
Date:
Sat Apr 17 10:22:14 2021 +0000
Revision:
1:03835eef0976
Parent:
0:fb5ea244d4f6
Child:
2:7e2fbb1f16d4
Fixing errors on wait time

Who changed what in which revision?

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