Okay so I have decided to use arduino for a school project... It was obviously a bad idea because I am in way over my head and now I'm just hoping it will work
The project is this- I am making a game. This game will include cards with holes punched out, as well as a card reader. The user will insert the card into the card reader, and the arduino within will use IR LEDs and IR detectors to determine the pattern of holes and no/holes in the card. The user will press a button (A/B/C/D) and if they get it right, green LEDs will flash. If they get it wrong, red LEDs will flash, and a green LED will show the correct answer.
I am getting a ton of error messages when I verify my program, and I hardly know where to begin to fix them. I know it is probably too much to ask from the casual forum browser but any helpful input would be appreciated.. I have not done much programming with arduino, only a little bit of Python. And I am not that good with Python either..
Here is my code, I hope the comments can help you to understand the intended function of the different parts.
const int IR1Pin = A0; //IR sensor #1
const int IR2Pin = A1; //IR sensor #2
const int IR3Pin = A2; //IR sensor #3
const int IR4Pin = A3; //IR sensor #4
const int IR5Pin = A4; //IR sensor #5
const int LEDAcorrectPin = 1; //LED answer A is correct (GREEN LED)
const int LEDBcorrectPin = 2; //LED answer B is correct
const int LEDCcorrectPin = 3; //LED answer C is correct
const int LEDDcorrectPin = 4; //LED answer D is correct
const int LEDAincorrectPin = 5; //LED answer A is incorrect (RED LED)
const int LEDBincorrectPin = 6; //LED answer B is incorrect
const int LEDCincorrectPin = 7; //LED answer C is incorrect
const int LEDDincorrectPin = 8; //LED answer D is incorrect
const int ButtonAPin = 9; //Pushbutton answer A
const int ButtonBPin = 10; //Pushbutton answer B
const int ButtonCPin = 11; //Pushbutton answer C
const int ButtonDPin = 12; //Pushbutton answer D
const int IRLEDPin = 13; //IR LEDs
const int cardbuttonPin = A5; //card in slot?
boolean buttonA = false;
boolean buttonB = false;
boolean buttonC = false;
boolean buttonD = false;
boolean cardin = false;
String answer = "";
String input = "";
void blink() {
digitalWrite(LEDAcorrectPin, HIGH)
digitalWrite(LEDBcorrectPin, HIGH)
digitalWrite(LEDCcorrectPin, HIGH)
digitalWrite(LEDDcorrectPin, HIGH)
}
void setup() {
pinMode(IR1Pin, INPUT);
pinMode(IR2Pin, INPUT);
pinMode(IR3Pin, INPUT);
pinMode(IR4Pin, INPUT);
pinMode(IR5Pin, INPUT);
pinMode(LEDAcorrectPin, OUTPUT);
pinMode(LEDBcorrectPin, OUTPUT);
pinMode(LEDCcorrectPin, OUTPUT);
pinMode(LEDDcorrectPin, OUTPUT);
pinMode(LEDAincorrectPin, OUTPUT);
pinMode(LEDBincorrectPin, OUTPUT);
pinMode(LEDCincorrectPin, OUTPUT);
pinMode(LEDDincorrectPin, OUTPUT);
pinMode(ButtonAPin, INPUT);
pinMode(ButtonBPin, INPUT);
pinMode(ButtonCPin, INPUT);
pinMode(ButtonDPin, INPUT);
pinMode(IRLEDPin, OUTPUT);
blink();
}
String read(){
///This function turns on the array of IR LEDs, then stores
///the values of the IR detectors to a string. This string matters
///because each individual card will have its own code, which will
///determine what the answer is.
digitalWrite(IRLEDPin, HIGH);
boolean IR1 = digitalRead(IR1Pin);
boolean IR2 = digitalRead(IR2Pin);
boolean IR3 = digitalRead(IR3Pin);
boolean IR4 = digitalRead(IR4Pin);
String code = "";
if (IR1==true){ //if there was an open hole in the card, add a 1
code += 1;
}
else; //if there was no hole in the card, add a 0
code += 0;
if (IR2==true){
code += 1;
}
else;
code += 0;
if (IR2==true){
code += 1;
}
else;
code += 0;
if (IR2==true){
code += 1;
}
else;
code += 0;
return code;
}
String answer(code){
///This function takes the code read by the IR detectors and
///can tell what the answer is for every code.
if (code=="00001");
answer = "A";
if (code=="00010");
answer = "A";
if (code=="00011");
answer = "A";
if (code=="00100");
answer = "A";
if (code=="00101");
answer = "A";
if (code=="00110");
answer = "A";
if (code=="00111");
answer = "A";
if (code=="01000");
answer = "A";
if (code=="01001");
answer = "B";
if (code=="01010");
answer = "B";
if (code=="01011");
answer = "B";
if (code=="01100");
answer = "B";
if (code=="01101");
answer = "B";
if (code=="01110");
answer = "B";
if (code=="01111");
answer = "B";
if (code=="10000");
answer = "B";
if (code=="10001");
answer = "C";
if (code=="10010");
answer = "C";
if (code=="10011");
answer = "C";
if (code=="10100");
answer = "C";
if (code=="10101");
answer = "C";
if (code=="10110");
answer = "C";
if (code=="10111");
answer = "C";
if (code=="11000");
answer = "C";
if (code=="11001");
answer = "D";
if (code=="11010");
answer = "D";
if (code=="11011");
answer = "D";
if (code=="11100");
answer = "D";
if (code=="11101");
answer = "D";
if (code=="11110");
answer = "D";
if (code=="11111");
answer = "D";
if (code=="00000");
answer = "D";
return answer
}
String input(){
///This function measures to see which button is pressed.
///The button is stored in "input"
buttonA=digitalRead(buttonAPin);
buttonB=digitalRead(buttonBPin);
buttonC=digitalRead(buttonCPin);
buttonD=digitalRead(buttonDPin);
if(buttonA==true){
input="A"
}
if(buttonB==true){
input="B"
}
if(buttonC==true){
input="C"
}
if(buttonD==true){
input="D"
}
return input
}
void correct(input, answer){
///this function compares the correct answer with the user input.
///if they are the same, it flashes all the LEDs
///If the user got the question wrong, it will flash the correct
///answer green and all the others red
if(input==answer){
blink();
}
else{
if (answer=="A"){
digitalWrite(LEDAcorrectPin, HIGH);
digitalWrite(LEDBincorrectPin, HIGH);
digitalWrite(LEDCincorrectPin, HIGH);
digitalWrite(LEDDincorrectPin, HIGH);
}
if (answer=="B"){
digitalWrite(LEDAincorrectPin, HIGH);
digitalWrite(LEDBcorrectPin, HIGH);
digitalWrite(LEDCincorrectPin, HIGH);
digitalWrite(LEDDincorrectPin, HIGH);
}
if (answer=="C"){
digitalWrite(LEDAincorrectPin, HIGH);
digitalWrite(LEDBincorrectPin, HIGH);
digitalWrite(LEDCcorrectPin, HIGH);
digitalWrite(LEDDincorrectPin, HIGH);
}
if (answer=="D"){
digitalWrite(LEDAincorrectPin, HIGH);
digitalWrite(LEDBincorrectPin, HIGH);
digitalWrite(LEDCincorrectPin, HIGH);
digitalWrite(LEDDcorrectPin, HIGH);
}
}
}
void main(){
cardbutton=digitalRead(cardbuttonPin);
if(cardbutton == HIGH){ ///if a card is inserted into the slot
blink(); ///blink all the LEDs
read(); ///read the card
answer(); ///use the code to determine what the answer is
input(); ///what button did the user press?
correct(); ///tell the user if they got it right or not
}
}
void loop(){
main(); ///run the main function
}