it still needs to count the total balls and count the balls individual and it needs the button to show those values and restart the program
so what the code can do is sort the balls physicaly and display the current colour
what i want the code to do extra is display the total counted balls and the total counted colours individual
here's the code
// rood groen blauw
//rode 25-40 70-90 65-78
//witte20-30 38-50 35-43
//blauwe40-50 60-80 40-60
#include <Servo.h>
#define S0 2
#define S1 3
#define S2 4
#define S3 5
#define OUT 6
Servo bovenServo;
Servo onderServo;
int frequency = 0;
int color=0;
void setup() {
pinMode(S0, OUTPUT);
pinMode(S1, OUTPUT);
pinMode(S2, OUTPUT);
pinMode(S3, OUTPUT);
pinMode(OUT, INPUT);
digitalWrite(S0, HIGH);
digitalWrite(S1, LOW);
bovenServo.attach(7);
onderServo.attach(8);
Serial.begin(9600);
}
void loop() {
bovenServo.write(115);
delay(1000);
for(int i = 115; i > 55; i--) {
bovenServo.write(i);
delay(2);
}
delay(500);
color = readColor();
delay(10);
switch (color) {
case 1:
onderServo.write(50);
break;
case 2:
onderServo.write(100);
break;
case 3:
onderServo.write(150);
break;
case 0:
break;
}
delay(500);
for(int i = 55; i > 29; i--) {
bovenServo.write(i);
delay(2);
}
delay(400);
for(int i = 29; i < 115; i++) {
bovenServo.write(i);
delay(2);
}
color=0;
}
int readColor() {
digitalWrite(S2, LOW);
digitalWrite(S3, LOW);
frequency = pulseIn(OUT, LOW);
int R = frequency;
Serial.print("R= ");
Serial.print(frequency);
Serial.print(" ");
delay(50);
digitalWrite(S2, HIGH);
digitalWrite(S3, HIGH);
frequency = pulseIn(OUT, LOW);
int G = frequency;
Serial.print("G= ");
Serial.print(frequency);
Serial.print(" ");
delay(50);
digitalWrite(S2, LOW);
digitalWrite(S3, HIGH);
frequency = pulseIn(OUT, LOW);
int B = frequency;
Serial.print("B= ");
Serial.print(frequency);
Serial.println(" ");
delay(50);
// rood groen blauw
//rode 25-40 70-90 65-78
//witte20-30 35-50 35-43
//blauwe40-50 60-80 40-60
if(R<50 & R>25 & G<90 & G>70){
color = 1; // Rood
//Serial.print("rood");
//Serial.print('\n');
}
if(G<50 & G>35 & B<45 &B>35){
color = 2; // wit
//Serial.print("wit");
//Serial.print('\n');
}
if(G<80 & G>60 & B<60 & B>40){
color = 3; // Blauw
//Serial.print("blauw");
//Serial.print('\n');
}
return color;
}