i don't really know what you mean with "It looks like you're returning a pointer to an item on the stack - that's a really Bad Idea, and probably unnecessary."
but indeed the code does not compile
the only error i get is : "error: invalid suffix "x2" on integer constant"
#include <Wire.h>
#include <Average.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(16x2, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); // Set the LCD I2C address
char EMIC;
int S0=2,S1=3,S2=4,S3=5, LED=6;
int OUT=7;
int K1=A0,K2=A1,K3=A2,K4=A4;
int OK=12,A=11,B=10,reset=9;
int blueTokens = 0;
int grnTokens = 0;
void setup() {
TCS3200_Setup(); // initialize color sensor
Serial.begin(9600); // Used to type in characters
lcd.begin(16,2); // initialize the lcd for 16 chars 2 lines, turn on backlight
lcd.setCursor(0,0); // Start at character 0 on line 0
lcd.print("welcome");
delay (1000);
lcd.clear();
RelayModuleSetup(); // initialize relay module
pinMode(OK,INPUT); // butons
pinMode(A,INPUT); // butons
pinMode(B,INPUT); // butons
pinMode(reset,INPUT); // butons
digitalWrite(K1,HIGH); // start motor
delay(1000);
}
void loop() {
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Green Coins");
lcd.setCursor(0,1);
lcd.print("Blue Coins");
if(ReadColor() == "blue"){
blueTokens++;
digitalWrite(K2,HIGH); // right bin
digitalWrite(K3,LOW);
delay (50);
}
else if(ReadColor() == "green"){
grnTokens++;
digitalWrite(K2,HIGH); //left bin
digitalWrite(K3,HIGH);
delay (50);
}
lcd.setCursor(13,0);
lcd.print(grnTokens);
delay(1);
lcd.setCursor(13,1);
lcd.print(blueTokens);
delay(1);
}
//********************************* FUNCTIONS COLOR SENSOR *********************************
void TCS3200_Setup() { //instellen van de digitale pin configuratie
pinMode(S0,OUTPUT);
pinMode(S1,OUTPUT);
pinMode(S2,OUTPUT);
pinMode(S3,OUTPUT);
pinMode(LED,OUTPUT);
pinMode(OUT,INPUT);
}
void TCS3200_On() {
digitalWrite(LED,HIGH); // Switch LED on
digitalWrite(S0,HIGH); //Output frequency scaling (100%)
digitalWrite(S1,HIGH);
delay(5);
}
void TCS3200_Off() {
digitalWrite(LED,LOW); // Switch LED off
digitalWrite(S0,LOW); //Power off sensor
digitalWrite(S1,LOW);
}
void NoFilter() { //Select no filter
digitalWrite(S2,HIGH);
digitalWrite(S3,LOW);
delay(5);
}
void RedFilter() { //Select red filter
digitalWrite(S2,LOW);
digitalWrite(S3,LOW);
delay(5);
}
void GreenFilter() { //Select green filter
digitalWrite(S2,HIGH);
digitalWrite(S3,HIGH);
delay(5);
}
void BlueFilter() { //Select blue filter
digitalWrite(S2,LOW);
digitalWrite(S3,HIGH);
delay(5);
}
char* ReadColor() { //0=white, 1=orange, 2=yellow, 3=red, 4=green, 5=blue, 6=object out of range
float FrequencyClear,FrequencyRed,FrequencyGreen,FrequencyBlue;
int PercentageRed,PercentageGreen,PercentageBlue;
TCS3200_On();
NoFilter();
FrequencyClear=500.0/pulseIn(OUT,LOW,10000); // Frequency in kHz
RedFilter();
FrequencyRed=500.0/pulseIn(OUT,LOW,10000); // Frequency in kHz
GreenFilter();
FrequencyGreen=500.0/pulseIn(OUT,LOW,10000); // Frequency in kHz
BlueFilter();
FrequencyBlue=500.0/pulseIn(OUT,LOW,10000); // Frequency in kHz
TCS3200_Off();
//Output frequency blue, green, red percentage represents the ratio of the
//respective color to the Clear channel absolute value:
PercentageRed=int((FrequencyRed/FrequencyClear)*100.0);
PercentageGreen=int((FrequencyGreen/FrequencyClear)*100.0);
PercentageBlue=int((FrequencyBlue/FrequencyClear)*100.0);
//Learned blue, green, red percentage values of different colors
int SavedColorRed[] = {
28,55,42,50,19,13 };
int SavedColorGreen[] = {
30,25,36,22,45,26 };
int SavedColorBlue[] = {
45,20,20,30,36,58 };
char* GetColor[] = {
"white","orange","yellow","red","green","blue","" };
int ColorArray[3];
int i_color;
int ClosestColor;
int MaxDiff;
int MinDiff=300;
if(FrequencyClear<1.5)ClosestColor=6; // Object out of range
else {
for (i_color=0; i_color<6; i_color++) { //Find closest color
ColorArray[0]=abs(SavedColorRed[i_color]-PercentageRed);
ColorArray[1]=abs(SavedColorGreen[i_color]-PercentageGreen);
ColorArray[2]=abs(SavedColorBlue[i_color]-PercentageBlue);
MaxDiff=maximum(ColorArray,3);
if (MaxDiff<MinDiff) {
MinDiff=MaxDiff;
ClosestColor=i_color;
}
}
}
return GetColor[ClosestColor];
}
//********************************* FUNCTIONS Relay Module *********************************
void RelayModuleSetup(){ //initialize relay module
pinMode(K1,OUTPUT);
pinMode(K2,OUTPUT);
pinMode(K3,OUTPUT);
pinMode(K4,OUTPUT);
digitalWrite(K1,LOW);
digitalWrite(K2,LOW);
digitalWrite(K3,LOW);
digitalWrite(K4,LOW);
}