Hi All! Doing the Arduino Dice project. Here is my code:
volatile int switchPin = 2;
int selectPin = 11;
bool spinReverse = false;
const int leds [6][6]{
{7, 0},
{3, 4, 0},
{1, 6, 7, 0},
{1, 2, 5, 6, 0},
{1, 2, 5, 6, 7, 0},
{1, 2, 3, 4, 5, 6}
};
const int spinnerLeds[6][1]{
{1},
{2},
{4},
{5},
{3},
};
volatile int buttonMenu = 0;
int buttonState = 0;
int randomRoll = 0;
int loopDelay = 400;
int rollDelay = 2000;
bool currentState = true;
void setup() {
pinMode(4 , OUTPUT);
pinMode(5 , OUTPUT);
pinMode(6 , OUTPUT);
pinMode(7 , OUTPUT);
pinMode(8 , OUTPUT);
pinMode(9 , OUTPUT);
pinMode(10 , OUTPUT);
pinMode(selectPin , INPUT_PULLUP);
pinMode(switchPin , INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(switchPin), SwitchButton, CHANGE);
TurnOff();
}
void loop() {
SelectButton();
switch (buttonMenu)
{
case 1:
{
if (currentState)
{
TurnOff();
}
currentState = false;
break;
}
case 2:
{
for (int i = 0; i < 6; i++)
{
TurnOn(i);
}
currentState = true;
break;
}
{
Spinner();
currentState = true;
break;
}
}
}
void SelectButton()
{
CheckButtonState();
if (buttonMenu == 99)
{
if (spinReverse)
{
SpinnerReverse();
}
else
{
Spinner();
}
}
randomSeed(analogRead(0));
randomRoll = random(0, 6);
Flash();
TurnOn(randomRoll);
delay(rollDelay);
TurnOff();
buttonMenu = 1;
}
}
void SwitchButton()
{
int reading = digitalRead(switchPin);
if (reading != buttonState) {
buttonState = reading;
if (buttonState == HIGH) {
buttonMenu++;
if (buttonMenu > 4)
{
buttonMenu = 1;
}
}
}
void CheckButtonState()
int currentReading = digitalRead(selectPin);
if (currentReading == 0)
{
buttonMenu = 99;
}
}
void TurnOff()
{
for (int x = 4; x < 11; x++)
{
digitalWrite(x, LOW);
}
}
void TurnAllOn()
{
for (int x = 4; x < 11; x++)
{
digitalWrite(x, HIGH);
}
}
void Flash()
{
for (int i = 0; i < 6; i++)
{
TurnAllOn();
delay(50);
TurnOff();
delay(50);
}
}
void Spinner()
{
for(int i = 0; i < 6; i++)
{
TurnOnLed(spinnerLeds*[0]);*
- delay(60);*
- }*
}
void SpinnerReverse()
{ - for (int i = 5; i >= 0; i--)*
- {*
_ TurnOnLed(spinnerLeds*[0]);_
_ delay(60);_
_ }_
_}_
void TurnOn(int dieRoll)
_{_
_ TurnOff();_
_ for (int i = 0; i <= 6; i++)_
_ {_
_ if (leds[dieRoll] == 0)
{
break;
}
TurnOnLed(leds[dieRoll]);
}
delay(loopDelay);
}
void TurnOnLed(int whichLed)
{
int newValue = whichLed + 3;
if (digitalRead(newValue) == LOW)
{
digitalWrite(newValue, HIGH);
}
else*
* {
digitalWrite(newValue, LOW);
}
CheckButtonState();*_
* }*
And this is the error message:
In function 'void setup()':
sketch_jun19a:36: error: 'SwitchButton' was not declared in this scope
* attachInterrupt(digitalPinToInterrupt(switchPin), SwitchButton, CHANGE);*
* ^*
sketch_jun19a:37: error: 'TurnOff' was not declared in this scope
* TurnOff();*
* ^*
/Users/yogigirl/Documents/Arduino/sketch_jun19a/sketch_jun19a.ino: In function 'void loop()':
sketch_jun19a:48: error: 'TurnOff' was not declared in this scope
* TurnOff();*
* ^*
sketch_jun19a:57: error: 'TurnOn' was not declared in this scope
* TurnOn(i);*
* ^*
sketch_jun19a:63: error: 'Spinner' was not declared in this scope
* Spinner();*
* ^*
/Users/yogigirl/Documents/Arduino/sketch_jun19a/sketch_jun19a.ino: In function 'void SelectButton()':
sketch_jun19a:74: error: 'CheckButtonState' was not declared in this scope
* CheckButtonState();*
* ^*
sketch_jun19a:79: error: 'SpinnerReverse' was not declared in this scope
* SpinnerReverse();*
* ^*
sketch_jun19a:83: error: 'Spinner' was not declared in this scope
* Spinner();*
* ^*
sketch_jun19a:88: error: 'Flash' was not declared in this scope
* Flash();*
* ^*
sketch_jun19a:90: error: 'TurnOn' was not declared in this scope
* TurnOn(randomRoll);*
* ^*
sketch_jun19a:92: error: 'TurnOff' was not declared in this scope
* TurnOff();*
* ^*
/Users/yogigirl/Documents/Arduino/sketch_jun19a/sketch_jun19a.ino: At global scope:
sketch_jun19a:95: error: expected declaration before '}' token
}
^
exit status 1
'SwitchButton' was not declared in this scope
I know it is a bit, so if it is too much guidance to how find the solution appreciated! It is a code I copied. Thank you in advance for any and all the help!