And my coding:
// constants won't change. They're used here to set pin numbers:
const int buttonPin40 = 40; // the number of the RED pushbutton pin
const int buttonPin41 = 41; // the number of the YELLOW pushbutton pin
const int buttonPin42 = 42; // the number of the GREEN pushbutton pin
const int buttonPin43 = 43; // the number of the BLUE pushbutton pin
const int buttonPin44 = 44; // the number of the ALPABET A pushbutton pin
const int buttonPin45 = 45; // the number of the ALPABET B pushbutton pin
const int buttonPin46 = 46; // the number of the ALPABET C pushbutton pin
const int buttonPin47 = 47; // the number of the ALPABET D pushbutton pin
const int buttonPin48 = 48; // the number of the NUMERIC 1 pushbutton pin
const int buttonPin49 = 49; // the number of the NUMERIC 2 pushbutton pin
const int buttonPin50 = 50; // the number of the NUMERIC 3 pushbutton pin
const int buttonPin51 = 51; // the number of the NUMERIC 4 pushbutton pin
const int ledPin22 = 22; // the number of the RED LED pin
const int ledPin23 = 23; // the number of the YELLOW LED pin
const int ledPin24 = 24; // the number of the GREEN LED pin
const int ledPin25 = 25; // the number of the BLUE LED pin
const int ledPin6 = 6; // the number of the BLUE LED pin
int fsrAnalogPin = A0; // FSR is connected to analog 0
int fsrReading; // the analog reading from the FSR resistor divider
int LEDbrightness;
// variables will change:
int buttonState40 = 0; // variable for reading the pushbutton status
int buttonState41 = 0; // variable for reading the pushbutton status
int buttonState42 = 0; // variable for reading the pushbutton status
int buttonState43 = 0; // variable for reading the pushbutton status
int buttonState44 = 0; // variable for reading the pushbutton status
int buttonState45 = 0; // variable for reading the pushbutton status
int buttonState46 = 0; // variable for reading the pushbutton status
int buttonState47 = 0; // variable for reading the pushbutton status
int buttonState48 = 0; // variable for reading the pushbutton status
int buttonState49 = 0; // variable for reading the pushbutton status
int buttonState50 = 0; // variable for reading the pushbutton status
int buttonState51 = 0; // variable for reading the pushbutton status
void setup() {
// initialize the LED pin as an output:
pinMode(ledPin22, OUTPUT);
pinMode(ledPin23, OUTPUT);
pinMode(ledPin24, OUTPUT);
pinMode(ledPin25, OUTPUT);
pinMode(ledPin6, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin40, INPUT);
pinMode(buttonPin41, INPUT);
pinMode(buttonPin42, INPUT);
pinMode(buttonPin43, INPUT);
pinMode(buttonPin44, INPUT);
pinMode(buttonPin45, INPUT);
pinMode(buttonPin46, INPUT);
pinMode(buttonPin47, INPUT);
pinMode(buttonPin48, INPUT);
pinMode(buttonPin49, INPUT);
pinMode(buttonPin50, INPUT);
pinMode(buttonPin51, INPUT);
Serial.begin(9600); // We'll send debugging information via the Serial monitor
}
void loop() {
// read the state of the pushbutton value:
buttonState40 = digitalRead(buttonPin40);
buttonState41 = digitalRead(buttonPin41);
buttonState42 = digitalRead(buttonPin42);
buttonState43 = digitalRead(buttonPin43);
buttonState44 = digitalRead(buttonPin44);
buttonState45 = digitalRead(buttonPin45);
buttonState46 = digitalRead(buttonPin46);
buttonState47 = digitalRead(buttonPin47);
buttonState48 = digitalRead(buttonPin48);
buttonState49 = digitalRead(buttonPin49);
buttonState50 = digitalRead(buttonPin50);
buttonState51 = digitalRead(buttonPin51);
// check if the pushbutton is pressed. If it is, the buttonState is HIGH:
if (buttonState40 == HIGH) {
// turn LED on:
digitalWrite(ledPin22, HIGH);
} else {
// turn LED off:
digitalWrite(ledPin22, LOW);
}
if (buttonState41 == HIGH) {
// turn LED on:
digitalWrite(ledPin23, HIGH);
} else {
// turn LED off:
digitalWrite(ledPin23, LOW);
}
if (buttonState42 == HIGH) {
// turn LED on:
digitalWrite(ledPin24, HIGH);
} else {
// turn LED off:
digitalWrite(ledPin24, LOW);
}
if (buttonState43 == HIGH) {
// turn LED on:
digitalWrite(ledPin25, HIGH);
} else {
// turn LED off:
digitalWrite(ledPin25, LOW);
}
if (buttonState44 == HIGH) {
// turn LED on:
digitalWrite(ledPin22, HIGH);
} else {
// turn LED off:
digitalWrite(ledPin22, LOW);
}
if (buttonState45 == HIGH) {
// turn LED on:
digitalWrite(ledPin22, HIGH);
} else {
// turn LED off:
digitalWrite(ledPin22, LOW);
}
if (buttonState46 == HIGH) {
// turn LED on:
digitalWrite(ledPin23, HIGH);
} else {
// turn LED off:
digitalWrite(ledPin23, LOW);
}
if (buttonState47 == HIGH) {
// turn LED on:
digitalWrite(ledPin23, HIGH);
} else {
// turn LED off:
digitalWrite(ledPin23, LOW);
}
if (buttonState48 == HIGH) {
// turn LED on:
digitalWrite(ledPin24, HIGH);
} else {
// turn LED off:
digitalWrite(ledPin24, LOW);
}
if (buttonState49 == HIGH) {
// turn LED on:
digitalWrite(ledPin24, HIGH);
} else {
// turn LED off:
digitalWrite(ledPin24, LOW);
}
if (buttonState50 == HIGH) {
// turn LED on:
digitalWrite(ledPin25, HIGH);
} else {
// turn LED off:
digitalWrite(ledPin25, LOW);
}
if (buttonState51 == HIGH) {
// turn LED on:
digitalWrite(ledPin25, HIGH);
} else {
// turn LED off:
digitalWrite(ledPin25, LOW);
}
fsrReading = analogRead(fsrAnalogPin);
Serial.print("Analog reading = ");
Serial.println(fsrReading);
if (fsrReading > 50) {
// we'll need to change the range from the analog reading (0-1023) down to the range
// used by analogWrite (0-255) with map!
LEDbrightness = map(fsrReading, 0, 1023, 0, 255);
// LED gets brighter the harder you press
analogWrite(ledPin6, LEDbrightness);
} else {
analogWrite(ledPin6, LOW);
}
delay(100);
}