/*
IR Breakbeam sensor demo!
*/
// Left red
#define LEDPIN 12
// Pin 12: Arduino has an LED connected on pin 12
// Pin 11: Teensy 2.0 has the LED on pin 11
// Pin 6: Teensy++ 2.0 has the LED on pin 6
// Pin 12: Teensy 3.0 has the LED on pin 12
#define SENSORPIN 3
// variables will change:
int sensorState = 3, lastState = 12; // variable for reading the pushbutton status
void setup() {
// initialize the LED pin as an output:
pinMode(LEDPIN, OUTPUT);
// initialize the sensor pin as an input:
pinMode(SENSORPIN, INPUT);
digitalWrite(SENSORPIN, HIGH); // turn on the pullup
Serial.begin(9600);
}
void loop() {
// read the state of the pushbutton value:
sensorState = digitalRead(SENSORPIN);
// check if the sensor beam is broken
// if it is, the sensorState is LOW:
if (sensorState == LOW) {
// turn LED on:
digitalWrite(LEDPIN, HIGH); int led = 12;
pinMode(led, OUTPUT);
digitalWrite(led, HIGH);
delay(3000);
}
else {
// turn LED off:
digitalWrite(LEDPIN, LOW);
}
if (sensorState && !lastState) {
Serial.println("Unbroken");
}
if (!sensorState && lastState) {
Serial.println("Broken");
}
lastState = sensorState;
}
// Left Blue
#define LEDPIN 11
// Pin 11: Arduino has an LED connected on pin 11
// Pin 11: Teensy 2.0 has the LED on pin 11
// Pin 6: Teensy++ 2.0 has the LED on pin 6
// Pin 11: Teensy 3.0 has the LED on pin 11
#define SENSORPIN 4
// variables will change:
int sensorState = 3, lastState = 11; // variable for reading the pushbutton status
void setup() {
// initialize the LED pin as an output:
pinMode(LEDPIN, OUTPUT);
// initialize the sensor pin as an input:
pinMode(SENSORPIN, INPUT);
digitalWrite(SENSORPIN, HIGH); // turn on the pullup
Serial.begin(9600);
}
void loop() {
// read the state of the pushbutton value:
sensorState = digitalRead(SENSORPIN);
// check if the sensor beam is broken
// if it is, the sensorState is LOW:
if (sensorState == LOW) {
// turn LED on:
digitalWrite(LEDPIN, HIGH); int led = 11;
pinMode(led, OUTPUT);
digitalWrite(led, HIGH);
delay(3000);
}
else {
// turn LED off:
digitalWrite(LEDPIN, LOW);
}
if (sensorState && !lastState) {
Serial.println("Unbroken");
}
if (!sensorState && lastState) {
Serial.println("Broken");
}
lastState = sensorState;
}
Arduino: 1.8.2 (Windows 7), Board: "Arduino/Genuino Uno"
multiircode:65: error: redefinition of 'int sensorState'
int sensorState = 3, lastState = 11; // variable for reading the pushbutton status
^
C:\Users\User\Documents\Arduino\multiircode\multiircode.ino:15:5: note: 'int sensorState' previously defined here
int sensorState = 3, lastState = 12; // variable for reading the pushbutton status
^
multiircode:65: error: redefinition of 'int lastState'
int sensorState = 3, lastState = 11; // variable for reading the pushbutton status
^
C:\Users\User\Documents\Arduino\multiircode\multiircode.ino:15:22: note: 'int lastState' previously defined here
int sensorState = 3, lastState = 12; // variable for reading the pushbutton status
^
C:\Users\User\Documents\Arduino\multiircode\multiircode.ino: In function 'void setup()':
multiircode:67: error: redefinition of 'void setup()'
void setup() {
^
C:\Users\User\Documents\Arduino\multiircode\multiircode.ino:17:6: note: 'void setup()' previously defined here
void setup() {
^
C:\Users\User\Documents\Arduino\multiircode\multiircode.ino: In function 'void loop()':
multiircode:77: error: redefinition of 'void loop()'
void loop() {
^
C:\Users\User\Documents\Arduino\multiircode\multiircode.ino:27:6: note: 'void loop()' previously defined here
void loop() {
^
exit status 1
redefinition of 'int sensorState'
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
Pauls, I know im missing the most basic step, ive been trying to figure out where im going wrong. I do want your help I see what you mean but my half a brain cant see it.