I have been makeing this project but i have difficulties, and cant find the problem
pins 11, and 12 are always on after the start they should only be on when pressing the coresponding button, or at the end if that color won.
its a game like oddball of halo ball changes hands team to team gaining points for each as they hold their teams button. 1st to rack up all the points wins.
the point counting works, but not the led (to let you know what button is being pressed) redPin, greenPin; or the white led that lights up if your pressing a team button, and you are behind in the score.
score set low to 10 for testing.
Name: CrazySkull ( "oddball" type game)
Description:
The circuit:
*
*
*
Created AUG 2012
By: Brad Nelson
-Mainstream Productions-
*/
// Constants:
// Outputs:
const int redPin = 12; //red led with resistor
const int greenPin = 11; // green led and resitor
const int whitePin = 10; //white led resitor to 3v
const int sirenPin = 7; // set to pin 7 (off) pin 8 (on)
const int brightPin = 9; //relay to 1W led
// Inputs:
const int redButton = 5; //10k pulldown
const int greenButton = 6; // 10k pulldown
const int startSensor = 4; //10k pulldown
// Variables:
// Read: (has something physicaly attached)
int redState = LOW;
int greenState = LOW;
// Made: (has nothing physicaly attached)
int pointValue = 10; // setable point value for game end (in arbitrary units)
int greenCount = 0;
int redCount = 0;
void setup() {
// initialize the pins outputs:
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(whitePin, OUTPUT);
pinMode(sirenPin, OUTPUT);
pinMode(brightPin, OUTPUT);
// initialize the pins inputs:
pinMode(redButton, INPUT);
pinMode(greenButton, INPUT);
pinMode(startSensor, INPUT);
digitalWrite(redPin, HIGH);
digitalWrite(greenPin, HIGH);
digitalWrite(whitePin, HIGH);
digitalWrite(brightPin, HIGH);
digitalWrite(sirenPin, HIGH);
delay(500);
digitalWrite(sirenPin, LOW);
delay(500);
digitalWrite(sirenPin, HIGH);
delay(500);
digitalWrite(sirenPin, LOW);
delay(500);
digitalWrite(sirenPin, HIGH);
delay(500);
digitalWrite(sirenPin, LOW);
digitalWrite(redPin, LOW);
digitalWrite(greenPin, LOW);
digitalWrite(whitePin, LOW);
}
void loop(){
//
greenState = digitalRead(greenButton);
redState = digitalRead(redButton);
if(redState == HIGH, greenState == LOW)
{
redTeam(); // run redTeam
}
if(greenState == HIGH, redState == LOW)
{
greenTeam(); // run greenTeam
}
if(pointValue <= redCount)
{
win();
}
if(pointValue <= greenCount)
{
win();
}
}
//000000000000000000000000000000000000000
void redTeam(){
redState = digitalRead(redButton);
digitalWrite(redPin, HIGH);
digitalWrite(greenPin, LOW);
if(redState == HIGH)
{
redCount++;
delay(500);
if(redCount < greenCount)
{
digitalWrite(whitePin, HIGH);
}
if(redCount >= greenCount)
{
digitalWrite(whitePin, LOW);
}
}
}
void greenTeam(){
greenState = digitalRead(greenButton);
digitalWrite(greenPin, HIGH);
digitalWrite(redPin, LOW);
if(greenState == HIGH)
{
greenCount++;
delay(500);
if(greenCount < redCount)
{
digitalWrite(whitePin, HIGH);
}
if(greenCount >= redCount)
{
digitalWrite(whitePin, LOW);
}
}
}
void win(){
digitalWrite(brightPin, LOW);
digitalWrite(whitePin, HIGH);
if(redCount >= greenCount)
{
digitalWrite(redPin, HIGH);
digitalWrite(greenPin, LOW);
}
digitalWrite(whitePin, HIGH);
if(greenCount >= redCount)
{
digitalWrite(greenPin, HIGH);
digitalWrite(redPin, LOW);
}
delay(500);
digitalWrite(sirenPin,HIGH);
digitalWrite(brightPin, HIGH);
digitalWrite(whitePin, LOW);
delay(500);
digitalWrite(sirenPin,LOW);
digitalWrite(brightPin, LOW);
digitalWrite(whitePin, HIGH);
delay(1000);
digitalWrite(sirenPin,HIGH);
digitalWrite(brightPin, HIGH);
digitalWrite(whitePin, LOW);
delay(500);
digitalWrite(sirenPin,LOW);
digitalWrite(brightPin, LOW);
digitalWrite(whitePin, HIGH);
delay(1000);
digitalWrite(sirenPin,HIGH);
digitalWrite(brightPin, HIGH);
digitalWrite(whitePin, LOW);
delay(500);
digitalWrite(sirenPin,LOW);
digitalWrite(brightPin, LOW);
digitalWrite(whitePin, HIGH);
delay(1000);
digitalWrite(sirenPin,HIGH);
digitalWrite(brightPin, HIGH);
digitalWrite(whitePin, LOW);
delay(2000);
digitalWrite(sirenPin,LOW);
digitalWrite(brightPin, LOW);
digitalWrite(whitePin, HIGH);
}