Lab 4ES_ColourMixer John Curran T00214119

Dependencies:   mbed

Committer:
johnc89
Date:
Sat Apr 17 09:26:21 2021 +0000
Revision:
0:fb5ea244d4f6
Child:
1:03835eef0976
working on errors

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 0:fb5ea244d4f6 22 wait=(0.5);
johnc89 0:fb5ea244d4f6 23
johnc89 0:fb5ea244d4f6 24 }
johnc89 0:fb5ea244d4f6 25 if(ADCdata>0.2 && ADCdata <= 0.4) {
johnc89 0:fb5ea244d4f6 26 pc.printf ( " ADCdata >0.2-<=0.4");
johnc89 0:fb5ea244d4f6 27 redled = 0;
johnc89 0:fb5ea244d4f6 28 greenled=1;
johnc89 0:fb5ea244d4f6 29 blueled= 1;
johnc89 0:fb5ea244d4f6 30 wait=(0.5);
johnc89 0:fb5ea244d4f6 31
johnc89 0:fb5ea244d4f6 32 }
johnc89 0:fb5ea244d4f6 33 if(ADCdata>0.4 && ADCdata <= 0.8) {
johnc89 0:fb5ea244d4f6 34 pc.printf ( " ADCdata >0.4-<=0.8");
johnc89 0:fb5ea244d4f6 35 redled = 1;
johnc89 0:fb5ea244d4f6 36 greenled=0;
johnc89 0:fb5ea244d4f6 37 blueled= 1;
johnc89 0:fb5ea244d4f6 38 wait=(0.5);
johnc89 0:fb5ea244d4f6 39
johnc89 0:fb5ea244d4f6 40 }
johnc89 0:fb5ea244d4f6 41 if(ADCdata>0.8 && ADCdata <= 0.9) {
johnc89 0:fb5ea244d4f6 42 pc.printf ( " ADCdata >0.8-<=0.9");
johnc89 0:fb5ea244d4f6 43 redled = 1;
johnc89 0:fb5ea244d4f6 44 greenled=1;
johnc89 0:fb5ea244d4f6 45 blueled= 0;
johnc89 0:fb5ea244d4f6 46 wait=(0.5);
johnc89 0:fb5ea244d4f6 47
johnc89 0:fb5ea244d4f6 48 }
johnc89 0:fb5ea244d4f6 49 if(ADCdata>0.9 && ADCdata <= 1.0) {
johnc89 0:fb5ea244d4f6 50 pc.printf ( " ADCdata >0.9-<=1.0");
johnc89 0:fb5ea244d4f6 51 redled = 0;
johnc89 0:fb5ea244d4f6 52 greenled=0;
johnc89 0:fb5ea244d4f6 53 blueled= 1;
johnc89 0:fb5ea244d4f6 54 wait=(0.5);
johnc89 0:fb5ea244d4f6 55
johnc89 0:fb5ea244d4f6 56 }
johnc89 0:fb5ea244d4f6 57 }
johnc89 0:fb5ea244d4f6 58 }