Hey Forum,
I'm working on a sketch that uses analog input from flex sensors to turn on LEDs. I keep getting an "error: using obsolete binding" message for my void loop functions however I'm pretty sure I need them in order for the sketch to operate the way I've intended. This is the sketch:
//Flex Sensor Pin (flexPin)
//the analog pin the Flex Sensor is connected to
int flexPin1 = 0;
int flexPin2 = 1;
int flexPin3 = 2;
int flexPin4 = 3;
int flexPin5 = 4;
void setup() {
for (int i=2; i<9; i++){
pinMode(i, OUTPUT);
for (int i2=9; i2<16; i2++){
pinMode(i2, OUTPUT);
for (int i3=16; i2<23; i3++){
pinMode(i3, OUTPUT);
for (int i4=23; i2<30; i4++){
pinMode(i4, OUTPUT);
for (int i5=30; i2<37; i5++){
pinMode(i5, OUTPUT);
}
}
}
}
}
}
void loop(){
for (int i=2; i<9; i++)
{
digitalWrite(i, LOW);
}
for (int i2=9; i<16; i2++)
{
digitalWrite(i2, LOW);
}
for (int i3=16; i<23; i3++)
{
digitalWrite(i3, LOW);
}
for (int i4=23; i<30; i4++)
{
digitalWrite(i4, LOW);
}
for (int i5=30; i<37; i5++)
{
digitalWrite(i5, LOW);
}
/* Read the flex Level
Adjust the value 130 to 275 to span 28 to 36
The values 130 and 275 may need to be widened to suit
the minimum and maximum flex levels being read by the
Analog pin */
int lightLevel = map(analogRead(flexPin1), 175, 250, 2, 8);
int lightLevel2 = map(analogRead(flexPin2), 175, 250, 9, 15);
int lightLevel3 = map(analogRead(flexPin3), 175, 250, 16, 22);
int lightLevel4 = map(analogRead(flexPin4), 175, 250, 23, 29);
int lightLevel5 = map(analogRead(flexPin5), 175, 250, 30, 36);
// Make sure the value is between 4 and 13, to turn on an LED
int ledON = constrain(lightLevel, 2, 8);
int ledON2 = constrain(lightLevel2, 9, 15);
int ledON3 = constrain(lightLevel3, 16, 22);
int ledON4 = constrain(lightLevel4, 23, 29);
int ledON5 = constrain(lightLevel5, 30, 36);
//Blink the LED on
blink(ledON, 10,1);
blink(ledON2, 10,1);
blink(ledON3, 10,1);
blink(ledON4, 10,1);
blink(ledON5, 10,1);
}
// The blink function - used to turn the LEDs on and off
void blink(int LEDPin, int onTime, int offTime){
// Turn the LED on
digitalWrite(LEDPin, HIGH);
// Delay so that you can see the LED go On.
delay(onTime);
// Turn the LED Off
digitalWrite(LEDPin, LOW);
// Delay so that you can see the LED go On.
delay(offTime);
}
// The blink function - used to turn the LEDs on and off
void blink2(int LEDPin2, int onTime2, int offTime2){
// Turn the LED on
digitalWrite(LEDPin2, HIGH);
// Delay so that you can see the LED go On.
delay(onTime2);
// Turn the LED Off
digitalWrite(LEDPin2, LOW);
// Delay so that you can see the LED go On.
delay(offTime2);
}
// The blink function - used to turn the LEDs on and off
void blink3(int LEDPin3, int onTime3, int offTime3){
// Turn the LED on
digitalWrite(LEDPin3, HIGH);
// Delay so that you can see the LED go On.
delay(onTime3);
// Turn the LED Off
digitalWrite(LEDPin3, LOW);
// Delay so that you can see the LED go On.
delay(offTime3);
}
// The blink function - used to turn the LEDs on and off
void blink4(int LEDPin4, int onTime4, int offTime4){
// Turn the LED on
digitalWrite(LEDPin4, HIGH);
// Delay so that you can see the LED go On.
delay(onTime4);
// Turn the LED Off
digitalWrite(LEDPin4, LOW);
// Delay so that you can see the LED go On.
delay(offTime4);
}
// The blink function - used to turn the LEDs on and off
void blink5(int LEDPin5, int onTime5, int offTime5){
// Turn the LED on
digitalWrite(LEDPin5, HIGH);
// Delay so that you can see the LED go On.
delay(onTime5);
// Turn the LED Off
digitalWrite(LEDPin5, LOW);
// Delay so that you can see the LED go On.
delay(offTime5);
}
Additionally, I need to make a revision to control this entire loop with momentary push button similar to this:
I have found coding for simple switches but I am confused about digitally writing values. I am working to combine the sketch above with the following sketch:
/*
Button
Turns on and off a light emitting diode(LED) connected to digital
pin 13, when pressing a pushbutton attached to pin 2.
The circuit:
* LED attached from pin 13 to ground
* pushbutton attached to pin 2 from +5V
* 10K resistor attached to pin 2 from ground
* Note: on most Arduinos there is already an LED on the board
attached to pin 13.
created 2005
by DojoDave <http://www.0j0.org>
modified 30 Aug 2011
by Tom Igoe
This example code is in the public domain.
http://www.arduino.cc/en/Tutorial/Button
*/
// constants won't change. They're used here to
// set pin numbers:
const int buttonPin = 2; // the number of the pushbutton pin
const int ledPin = 13; // the number of the LED pin
// variables will change:
int buttonState = 0; // variable for reading the pushbutton status
void setup() {
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
}
void loop(){
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (buttonState == HIGH) {
// turn LED on:
digitalWrite(ledPin, HIGH);
}
else {
// turn LED off:
digitalWrite(ledPin, LOW);
Any assistance is greatly appreciated. Thanks!
Moderator edit: Subject line amended. (Nick Gammon)