Hello all,
I recently started getting back to my antics and picked up an old project once again to finally finish, I came back to see a piece of code that just keeps giving me errors and I don't understand why?
correct me if I'm wrong here but I correctly declared all the listed errors
these are my errors
C:\Users\ErikD\Documents\Arduino\final_headr2d2\final_headr2d2.ino: In function 'void setup()':
final_headr2d2:22:3: error: 'blinkstartMillis' was not declared in this scope
blinkstartMillis = millis(); //initial start time
^~~~~~~~~~~~~~~~
C:\Users\ErikD\Documents\Arduino\final_headr2d2\final_headr2d2.ino:22:3: note: suggested alternative: 'blinkStartMillis'
blinkstartMillis = millis(); //initial start time
^~~~~~~~~~~~~~~~
blinkStartMillis
final_headr2d2:23:3: error: 'headstartMillis' was not declared in this scope
headstartMillis = millis(); //initial start time
^~~~~~~~~~~~~~~
C:\Users\ErikD\Documents\Arduino\final_headr2d2\final_headr2d2.ino:23:3: note: suggested alternative: 'headStartMillis'
headstartMillis = millis(); //initial start time
^~~~~~~~~~~~~~~
headStartMillis
final_headr2d2:27:2: error: 'setColourRgb' was not declared in this scope
setColourRgb(0,0,0);
^~~~~~~~~~~~
C:\Users\ErikD\Documents\Arduino\final_headr2d2\final_headr2d2.ino: In function 'void Blink()':
final_headr2d2:43:24: error: 'blinkstartMillis' was not declared in this scope
if (currentMillis - blinkstartMillis >= blinkperiod) //test whether the period has elapsed
^~~~~~~~~~~~~~~~
C:\Users\ErikD\Documents\Arduino\final_headr2d2\final_headr2d2.ino:43:24: note: suggested alternative: 'blinkStartMillis'
if (currentMillis - blinkstartMillis >= blinkperiod) //test whether the period has elapsed
^~~~~~~~~~~~~~~~
blinkStartMillis
final_headr2d2:58:6: error: 'setColourRgb' was not declared in this scope
setColourRgb(rgbColour[0], rgbColour[1], rgbColour[2]);
^~~~~~~~~~~~
C:\Users\ErikD\Documents\Arduino\final_headr2d2\final_headr2d2.ino:58:6: note: suggested alternative: 'decColour'
setColourRgb(rgbColour[0], rgbColour[1], rgbColour[2]);
^~~~~~~~~~~~
decColour
final_headr2d2:78:76: error: a function-definition is not allowed here before '{' token
void setColourRgb(unsigned int red, unsigned int green, unsigned int blue) {
^
C:\Users\ErikD\Documents\Arduino\final_headr2d2\final_headr2d2.ino: In function 'void Head()':
final_headr2d2:86:23: error: 'headstartMillis' was not declared in this scope
if (currentMillis - headstartMillis >= headperiod) //test whether the period has elapsed
^~~~~~~~~~~~~~~
C:\Users\ErikD\Documents\Arduino\final_headr2d2\final_headr2d2.ino:86:23: note: suggested alternative: 'headStartMillis'
if (currentMillis - headstartMillis >= headperiod) //test whether the period has elapsed
^~~~~~~~~~~~~~~
headStartMillis
final_headr2d2:89:3: error: 'OneStep' was not declared in this scope
OneStep(false);
^~~~~~~
final_headr2d2:93:3: error: 'OneStep' was not declared in this scope
OneStep(true);
^~~~~~~
final_headr2d2:96:23: error: a function-definition is not allowed here before '{' token
void OneStep(bool dir){
^
exit status 1
'blinkstartMillis' was not declared in this scope
can someone point me in the right direction? I'll update you if the program runs, and then again if it works in practice. Thank you for your time!
also FYI I'm sorta kinda a novice and I also haven't coded in awhile.
I recently started getting back to my antics and picked up an old project once again to finally finish, I came back to see a piece of code that just keeps giving me errors and I don't understand why?
Code:
#include <Stepper.h>
//Written By Nikodem Bartnik - nikodembartnik.pl
#define STEPPER_PIN_1 8
#define STEPPER_PIN_2 7
#define STEPPER_PIN_3 6
#define STEPPER_PIN_4 5
#define motorSteps 400
int pinArray[] = {13, 12};
int count = 0;
float minDelay = 125;
float maxDelay = 250;
const int redPin = 11;
const int bluePin = 10;
int step_number = 0;
unsigned long blinkStartMillis;
unsigned long headStartMillis;
unsigned long currentMillis;
const unsigned long blinkperiod = 1000; //the value is a number of milliseconds, ie 1 second
const unsigned long headperiod = 1000; //the value is a number of milliseconds, ie 1 second
void setup() {
blinkstartMillis = millis(); //initial start time
headstartMillis = millis(); //initial start time
for (count=0;count<2;count++) {
pinMode(pinArray[count], OUTPUT);
// Start off with the LED off.
setColourRgb(0,0,0);
}
pinMode(STEPPER_PIN_1, OUTPUT);
pinMode(STEPPER_PIN_2, OUTPUT);
pinMode(STEPPER_PIN_3, OUTPUT);
pinMode(STEPPER_PIN_4, OUTPUT);
}
void loop() {
currentMillis = millis(); //get the current "time" (actually the number of milliseconds since the program started)
Blink();
Head();
}
void Blink(){
if (currentMillis - blinkstartMillis >= blinkperiod) //test whether the period has elapsed
{
delay(random(minDelay, maxDelay));
unsigned int rgbColour[3];
// Start off with red.
rgbColour[0] = 255;
rgbColour[1] = 0;
rgbColour[2] = 0;
// Choose the colours to increment and decrement.
for (int decColour = 0; decColour < 3; decColour += 1) {
int incColour = decColour == 2 ? 0 : decColour + 1;
// cross-fade the two colours.
for(int i = 0; i < 255; i += 1) {
rgbColour[decColour] -= 1;
rgbColour[incColour] += 1;
setColourRgb(rgbColour[0], rgbColour[1], rgbColour[2]);
delay(5);
}
}
for (count=0;count<1;count++) {
digitalWrite(pinArray[count], HIGH);
delay(random(minDelay, maxDelay));
digitalWrite(pinArray[count + 1], HIGH);
delay(random(minDelay, maxDelay));
digitalWrite(pinArray[count], LOW);
delay(random(minDelay, maxDelay));
}
for (count=1;count>0;count--) {
digitalWrite(pinArray[count], HIGH);
delay(random(minDelay, maxDelay));
digitalWrite(pinArray[count - 1], HIGH);
delay(random(minDelay, maxDelay));
digitalWrite(pinArray[count], LOW);
delay(random(minDelay, maxDelay));
}
void setColourRgb(unsigned int red, unsigned int green, unsigned int blue) {
analogWrite(redPin, red);
analogWrite(bluePin, blue);
}
blinkstartMillis = currentMillis; //IMPORTANT to save the start time of the current LED state.
}
}
void Head(){
if (currentMillis - headstartMillis >= headperiod) //test whether the period has elapsed
{
for(int a = 0; a < 14000; a++){
OneStep(false);
delay(2);
}
for(int a = 0; a < 14000; a++){
OneStep(true);
delay(2);
}
void OneStep(bool dir){
if(dir){
switch(step_number){
case 0:
digitalWrite(STEPPER_PIN_1, HIGH);
digitalWrite(STEPPER_PIN_2, LOW);
digitalWrite(STEPPER_PIN_3, LOW);
digitalWrite(STEPPER_PIN_4, LOW);
break;
case 1:
digitalWrite(STEPPER_PIN_1, LOW);
digitalWrite(STEPPER_PIN_2, HIGH);
digitalWrite(STEPPER_PIN_3, LOW);
digitalWrite(STEPPER_PIN_4, LOW);
break;
case 2:
digitalWrite(STEPPER_PIN_1, LOW);
digitalWrite(STEPPER_PIN_2, LOW);
digitalWrite(STEPPER_PIN_3, HIGH);
digitalWrite(STEPPER_PIN_4, LOW);
break;
case 3:
digitalWrite(STEPPER_PIN_1, LOW);
digitalWrite(STEPPER_PIN_2, LOW);
digitalWrite(STEPPER_PIN_3, LOW);
digitalWrite(STEPPER_PIN_4, HIGH);
break;
}
}else{
switch(step_number){
case 0:
digitalWrite(STEPPER_PIN_1, LOW);
digitalWrite(STEPPER_PIN_2, LOW);
digitalWrite(STEPPER_PIN_3, LOW);
digitalWrite(STEPPER_PIN_4, HIGH);
break;
case 1:
digitalWrite(STEPPER_PIN_1, LOW);
digitalWrite(STEPPER_PIN_2, LOW);
digitalWrite(STEPPER_PIN_3, HIGH);
digitalWrite(STEPPER_PIN_4, LOW);
break;
case 2:
digitalWrite(STEPPER_PIN_1, LOW);
digitalWrite(STEPPER_PIN_2, HIGH);
digitalWrite(STEPPER_PIN_3, LOW);
digitalWrite(STEPPER_PIN_4, LOW);
break;
case 3:
digitalWrite(STEPPER_PIN_1, HIGH);
digitalWrite(STEPPER_PIN_2, LOW);
digitalWrite(STEPPER_PIN_3, LOW);
digitalWrite(STEPPER_PIN_4, LOW);
}
}
step_number++;
if(step_number > 3){
step_number = 0;
}
}
headstartMillis = currentMillis; //IMPORTANT to save the start time of the current LED state.
}
}
correct me if I'm wrong here but I correctly declared all the listed errors
these are my errors
C:\Users\ErikD\Documents\Arduino\final_headr2d2\final_headr2d2.ino: In function 'void setup()':
final_headr2d2:22:3: error: 'blinkstartMillis' was not declared in this scope
blinkstartMillis = millis(); //initial start time
^~~~~~~~~~~~~~~~
C:\Users\ErikD\Documents\Arduino\final_headr2d2\final_headr2d2.ino:22:3: note: suggested alternative: 'blinkStartMillis'
blinkstartMillis = millis(); //initial start time
^~~~~~~~~~~~~~~~
blinkStartMillis
final_headr2d2:23:3: error: 'headstartMillis' was not declared in this scope
headstartMillis = millis(); //initial start time
^~~~~~~~~~~~~~~
C:\Users\ErikD\Documents\Arduino\final_headr2d2\final_headr2d2.ino:23:3: note: suggested alternative: 'headStartMillis'
headstartMillis = millis(); //initial start time
^~~~~~~~~~~~~~~
headStartMillis
final_headr2d2:27:2: error: 'setColourRgb' was not declared in this scope
setColourRgb(0,0,0);
^~~~~~~~~~~~
C:\Users\ErikD\Documents\Arduino\final_headr2d2\final_headr2d2.ino: In function 'void Blink()':
final_headr2d2:43:24: error: 'blinkstartMillis' was not declared in this scope
if (currentMillis - blinkstartMillis >= blinkperiod) //test whether the period has elapsed
^~~~~~~~~~~~~~~~
C:\Users\ErikD\Documents\Arduino\final_headr2d2\final_headr2d2.ino:43:24: note: suggested alternative: 'blinkStartMillis'
if (currentMillis - blinkstartMillis >= blinkperiod) //test whether the period has elapsed
^~~~~~~~~~~~~~~~
blinkStartMillis
final_headr2d2:58:6: error: 'setColourRgb' was not declared in this scope
setColourRgb(rgbColour[0], rgbColour[1], rgbColour[2]);
^~~~~~~~~~~~
C:\Users\ErikD\Documents\Arduino\final_headr2d2\final_headr2d2.ino:58:6: note: suggested alternative: 'decColour'
setColourRgb(rgbColour[0], rgbColour[1], rgbColour[2]);
^~~~~~~~~~~~
decColour
final_headr2d2:78:76: error: a function-definition is not allowed here before '{' token
void setColourRgb(unsigned int red, unsigned int green, unsigned int blue) {
^
C:\Users\ErikD\Documents\Arduino\final_headr2d2\final_headr2d2.ino: In function 'void Head()':
final_headr2d2:86:23: error: 'headstartMillis' was not declared in this scope
if (currentMillis - headstartMillis >= headperiod) //test whether the period has elapsed
^~~~~~~~~~~~~~~
C:\Users\ErikD\Documents\Arduino\final_headr2d2\final_headr2d2.ino:86:23: note: suggested alternative: 'headStartMillis'
if (currentMillis - headstartMillis >= headperiod) //test whether the period has elapsed
^~~~~~~~~~~~~~~
headStartMillis
final_headr2d2:89:3: error: 'OneStep' was not declared in this scope
OneStep(false);
^~~~~~~
final_headr2d2:93:3: error: 'OneStep' was not declared in this scope
OneStep(true);
^~~~~~~
final_headr2d2:96:23: error: a function-definition is not allowed here before '{' token
void OneStep(bool dir){
^
exit status 1
'blinkstartMillis' was not declared in this scope
can someone point me in the right direction? I'll update you if the program runs, and then again if it works in practice. Thank you for your time!
also FYI I'm sorta kinda a novice and I also haven't coded in awhile.