Edit: Thanks everyone for your help. I've done tons of arduino projects and I've never managed to screw this up. I can't believe I didn't know that stup() and loop() are different scopes!!!
Thanks again!!
Hi all, I'm having a strange problem that I can't figure out. I have some variables declared in setup() but when I try to use them in loop() I get the old "not declared in this scope" error.
My code so far is:
// Include required libraries
#include <Wire.h>
#include <Adafruit_RGBLCDShield.h>
#include <utility/Adafruit_MCP23017.h>
Adafruit_RGBLCDShield lcd = Adafruit_RGBLCDShield();
#define RED 0x1
#define YELLOW 0x3
#define GREEN 0x2
#define TEAL 0x6
#define BLUE 0x4
#define VIOLET 0x5
#define WHITE 0x7
// OK at this point
void setup() {
// put your setup code here, to run once:
// Set up hall sensor pins
int hallPin = 0; // Pin to read for hall sensor output
int hallState = 0; // Set current hall sensor state
int lastHallState = 0; //previous hall output state
pinMode(hallPin, INPUT); // initialize Hall Pin as an input
// OK at this point
// Begin LCD Screen
lcd.begin(16, 2); // LCD has 16 columns and 2 rows
// Set up buttons
const int button1Pin = 3;
pinMode(button1Pin, INPUT);
const int button2Pin = 4;
pinMode(button2Pin, INPUT);
// OK at this point
// Set up variables
int jobLength = 1; // Length of current job in feet
int lobRemaining = 1; // Remaining linear feet in the job
int footageRolled = 1; // For tracking the linear footage through the roll
int footageIncrement = 1; // Calculate based on roll diameter, magnet spacing
int rollCount = 1;
Wire.pins(4, 5); // Sets data and clock pins for screen i2c
Serial.begin(9600); // Begin serial comminucation for diagnostics
}
void loop() {
// put your main code here, to run repeatedly:
// Display base menu
lcd.print("1 for new job");
lcd.setCursor(1, 0);
lcd.print("2 for counter");
// OK at this point
// Read pins for user input
int button1State = digitalRead(button1Pin);
int button2State = digitalRead(button2Pin);
// Problems now...
}
My error messages are:
C:\Users\vance.langer\Documents\Arduino\Test\Test.ino: In function 'void loop()':
Test:64: error: 'button1Pin' was not declared in this scope
int button1State = digitalRead(button1Pin);
^
Test:65: error: 'button2Pin' was not declared in this scope
int button2State = digitalRead(button2Pin);
^
exit status 1
'button1Pin' was not declared in this scope
Just what is going on here?