Hey i'm new to the Arduino world helping my daughter on a school project and im stumped on a problem with the LED brightness.
The micro controller is a :Adruino Mega 2650 Rev3
Anyway,
We have 14 LED light connected in series in banks of two, each bank connected to pins 30 thru 37 and to ground (no resistors in the circuit)
They are all supposed to flash at one time when the (if) statement conditions are meet it runs fail1 or fail2 scenario, it works but they are all very DIM.
Any help would be greatly appreciated.
void(* resetFunc) (void) = 0; //declare reset function @ address 0
#include <LiquidCrystal.h> // include the library code:
#include <Servo.h>
#define button_pin A3 // Defines the Button pin location on the Mega
long randnumber; // Defines the maxium numeric size of the random number
int randomnumber; // Defines that the random number is an integer(a number,not a letter)
LiquidCrystal lcd(7, 8, 9, 10, 11, 12); // Initializes LCD library & defines the Mega pins connected to the LCD pins
Servo myservo; // Initializes the Servo
int servospos = 150; // Start postition of servo
#define ledpin 13 // Defines the Winner LED pin location on the Mega
#define ledpin30 30 // Defines the Fail Lights Pin
#define ledpin32 32 // Defines the Fail Lights Pin
#define ledpin31 31 // Defines the Fail Lights Pin
#define ledpin33 33 // Defines the Fail Lights Pin
#define ledpin34 34 // Defines the Fail Lights Pin
#define ledpin35 35 // Defines the Fail Lights Pin
#define ledpin36 36 // Defines the Fail Lights Pin
#define ledpin37 37 // Defines the Fail Lights Pin
#define buzzerpin 4 // Defines buzzer pin on the Mega
int buttonState = 0; // Defines the data type for buttonState and starting value is 0
int count_value = 0; // Defines the data type as interger and starting value of 0 for the counter
int prestate = 0; // Defines the data type as interger and starting value of 0 for the button prestate
int S = 60; // counts down 60 seconds
void setup()
{
Serial.begin(9600);
randomSeed(analogRead(0)); // Tells the random number generator to use the Mega's analog pinA0 to listen for electrical noise and grabs a seed number from the noise to start the random sequense.
Serial.begin(9600); // Turns on the serial port to use the PC serial monitor for debugging.
lcd.begin(16, 2); // Set's up the LCD's number of columns and rows:
randnumber = random(1, 11); // Defines the Random Number Range to be between 1-5 (Note:The number listed as the upper range will not be genrated)
Serial.println(randnumber); // Print to Serial port for debuging
lcd.setCursor(8, 0); // Sets the LCD cursor to column 8, line 0 (Note: line 0 is the top line)
lcd.print(randnumber); // Prints the random number to the LCD
lcd.setCursor(8, 1); // sets the LCD cursor to column 8, line 1 (Note: line 1 is the botton line)
lcd.print(count_value); // Prints the number of button presses since reset
myservo.attach(3); // Defines what pin the servo's signal wire is connected to on the Mega.
myservo.write(servospos); // Moves the servo to the globaly defined starting postion[Box closed]so its ready when needed (position -> 30°)
pinMode(ledpin, OUTPUT); //defines LED pin is an Output
pinMode(button_pin, INPUT); //defined LED pin is an Input
pinMode(buzzerpin, OUTPUT); //defined LED pin is an Input
lcd.setCursor(8, 1); // sets the LCD cursor to column 8, line 1 (Note: line 1 is the botton line)
lcd.print(count_value); // Prints / updates the number of button presses since reset
Serial.println (S);
S--;
delay(1000);
}
void loop ()
{
if (S < 0)
{
M--;
S = 59;
}
if (M < 0)
{
H--;
M = 59;
}
if (H < 0) {
H = 0;
M = 0;
S = 0;
} if (M > 9)
{
Serial.println (S);
}
else
{
Serial.println (S);
}
if (S > 9)
{
Serial.println (S);
}
else
{
Serial.println (S);
}
if (H > 9)
{
Serial.println (S);
}
else
{
Serial.println (S);
}
buttonState = digitalRead(button_pin); // Reads the current position of the button (pressed/high or not pressed/low )
if (buttonState == HIGH && prestate == 0) {
count_value++;
prestate = 1; // States if the button is pressed add 1 to prestate value
}
else if (buttonState == LOW) {
prestate = 0; // States if button is not pressed the prestate value is 0
}
lcd.setCursor(8, 1);
lcd.print(count_value); // Reprints the number of button presses since reset
// Fail Action if total button press count is less than random number
if ((count_value < randnumber) && (count_value != 0)) // If the count comparison is less than the random number & not equal to 0 this runs the LED and buzzer fail sequence!
digitalWrite(ledpin30, HIGH); digitalWrite(ledpin31, HIGH); digitalWrite(ledpin32, HIGH); digitalWrite(ledpin33, HIGH); digitalWrite(ledpin34, HIGH); digitalWrite(ledpin35, HIGH); digitalWrite(ledpin36, HIGH); digitalWrite(ledpin37, HIGH);
// delay(1000);
digitalWrite(ledpin30, LOW); digitalWrite(ledpin31, LOW); digitalWrite(ledpin32, LOW); digitalWrite(ledpin33, LOW); digitalWrite(ledpin34, LOW); digitalWrite(ledpin35, LOW); digitalWrite(ledpin36, LOW); digitalWrite(ledpin37, LOW);
//delay(1000);
digitalWrite(buzzerpin, LOW);
//delay(500);
digitalWrite(buzzerpin, HIGH);
//delay(1000);
digitalWrite(buzzerpin, LOW);
//delay(3000);
//winner Action if total button press count is equal to Random number
if (!(randnumber != count_value)) // compares random number to the button press count to see if they are the same if there are is opens the box & lights the winning LEDs flashes!
{
digitalWrite(ledpin, HIGH); // Turns on & off Winner LEDS
//delay(1000);
digitalWrite(ledpin, LOW);
// delay(500);
digitalWrite(ledpin, HIGH);
//delay(1000);
digitalWrite(ledpin, LOW);
// delay(500);
myservo.write(30);//myservo.write(servospos); //Tells Servo to Opens the box
// delay(000);
//lcd.setCursor(8, 1);
//lcd.print(count_value); // Prints the number of button presses since reset
}
else (count_value != 0);
digitalWrite(ledpin, LOW); // If the above two if statement are not true do we wait longer IF so how long until it completely resets?
lcd.setCursor(8, 1);
lcd.print(count_value); // Prints the number of button presses since reset
//Fail Action if total button press count is greater than Random number
if ((count_value > randnumber) && (count_value != 0)) //If the count comparison is greater than the random number this IF statement handles the LED and Buzzer fail alerts!
{
digitalWrite(ledpin30, HIGH); digitalWrite(ledpin31, HIGH); digitalWrite(ledpin32, HIGH); digitalWrite(ledpin33, HIGH); digitalWrite(ledpin34, HIGH); digitalWrite(ledpin35, HIGH); digitalWrite(ledpin36, HIGH); digitalWrite(ledpin37, HIGH);
// delay(1000);
digitalWrite(ledpin30, LOW); digitalWrite(ledpin31, LOW); digitalWrite(ledpin32, LOW); digitalWrite(ledpin33, LOW); digitalWrite(ledpin34, LOW); digitalWrite(ledpin35, LOW); digitalWrite(ledpin36, LOW); digitalWrite(ledpin37, LOW);
//delay(1000);
digitalWrite(buzzerpin, LOW);
//delay(500);
digitalWrite(buzzerpin, HIGH);
//delay(1000);
digitalWrite(buzzerpin, LOW);
}
}
//resetFunc(); //call reset
