error message and led messing up for code.
Z:\arduino\Voltage\Voltage.ino: In function ‘long int rgb(int, int, int)’:
Z:\arduino\Voltage\Voltage.ino:21:1: warning: no return statement in function returning non-void [-Wreturn-type]
}
^
code is below.
#define ANALOG_IN_Ch1 0
#define ANALOG_IN_Ch2 1
#define ANALOG_IN_Ch3 2
const int rgbred = 2;
const int rgbgrn = 3;
const int rgbblu = 4;
void setup(){
Serial.begin(19200);
pinMode(ANALOG_IN_Ch1,INPUT);
pinMode(ANALOG_IN_Ch2,INPUT);
pinMode(ANALOG_IN_Ch3,INPUT);
pinMode(rgbred,OUTPUT);
pinMode(rgbgrn,OUTPUT);
pinMode(rgbblu,OUTPUT);
}
long rgb(int red, int green, int blue) {
analogWrite(rgbred, (red));
analogWrite(rgbgrn, (green));
analogWrite(rgbblu, (blue));
}
void loop(){
int val1 = analogRead(ANALOG_IN_Ch1);
int val2 = analogRead(ANALOG_IN_Ch2);
int val3 = analogRead(ANALOG_IN_Ch3);
int cnt = 0;
int v1 = map(val1,0,1023,0,5.0);
int v2 = map(val2,0,1023,0,5.0);
int v3 = map(val3,0,1023,0,5.0);
if(v1 >= 4.8 || v1 == -1){cnt = cnt+1;}
if(v2 >= 4.8 || v2 == -1){cnt = cnt+1;}
if(v3 >= 4.8 || v3 == -1){cnt = cnt+1;}
if(cnt == 0){
rgb(255,0,0);
}else if(cnt == 1){
rgb(255,165,0);
}else if(cnt == 2){
rgb(255,255,0);
}else if(cnt == 3){
rgb(0,255,0);
}
//Serial.print(cnt);
Serial.print('H'); /* Unique header to identify start of message */
Serial.print(",");
Serial.print(val1,DEC);
Serial.print(",");
Serial.print(val2,DEC);
Serial.print(",");
Serial.print(val3,DEC);
Serial.print(","); /* Note that a comma is sent after the last field */
Serial.println(); /* send a cr/lf */
delay(90);
}
what im trying to do is when my 3 little caps reach at 5 volts the led is suppose to change colors for each one that gets full. but its constantly blinking from red to green and repeat.