Good morning and thank you in advance,
Summary:
Requiring assistance with translating two independent analog potentiometer signals from one arduino wireless via bluetooth to a second arduino and output the values on two independent led bar graphs.
When one potentiometer is adjusted from zero, the corresponding led bar graph will illuminate an increasing number of leds over the value of the potentiometer.
The inputs potentiometers and output led bar graphs are located on two separate boards and only will communicate via bluetooth.
I have successfully created the project with using a single arduino. The input consists of two independent 10k ohm potentiometers delivering analogRead signals to a MEGA 2560 and the resulting value is displayed on output pins to 20 leds, 10 per bar.
I need assistance to better understand the code for how to write the state of the potentiometer serial.write() of the master bt and use the state "".write() on the slave led board.
Hardware:
Board 1:
1x Mega 2560
2x 10k potentiometer
1x HC-06 bluetooth module
1x I2C Logic Level Converter
Board 2:
1x Mega 2560
1x HC-06 bluetooth module
1x I2C Logic Level Converter
20x led
20x 220 resistor
I appreciate you taking the time to assist and enlighten a new arduino member
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// LIBRARY
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#define analogPinBRAKE A1 // brake RED potentiometer
#define analogPinTHROTTLE A2 // throttle GREEN potentiometer
#define ledBarCountRED 10 // number of LEDs in RED array
#define ledBarCountGREEN 10 // number of LEDs in GREEN array
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// VARIABLES
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------
int ledBarPinsRED[] = {31, 30, 29, 28, 27, 26, 25, 24, 23, 22}; // an array of pin numbers to which RED LEDs are attached, 22-31
int ledBarPinsGREEN[] = {41, 40, 39, 38, 37, 36, 35, 34, 33, 32}; // an array of pin numbers to which GREEN LEDs are attached, 32-41
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// SETUP
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------
void setup(){
for (int thisBarLedRED = 0; thisBarLedRED < ledBarCountRED; thisBarLedRED++) {pinMode(ledBarPinsRED[thisBarLedRED], OUTPUT);} // an array of pin array and set them all to output
for (int thisBarLedGREEN = 0; thisBarLedGREEN < ledBarCountGREEN; thisBarLedGREEN++) {pinMode(ledBarPinsGREEN[thisBarLedGREEN], OUTPUT);} // an array of pin array and set them all to output
}
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// MAIN LOOP
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------
void loop(){
int sensorReadingBRAKE = analogRead(analogPinBRAKE); // read the BRAKE potentiometer
int ledSensorBRAKE = map(sensorReadingBRAKE, 0 , 1023, 0, ledBarCountRED); // map the result to a range from 0 to the number of LEDs for BRAKE bar
int sensorReadingTHROTTLE = analogRead(analogPinTHROTTLE); // read the TROTTLE potentiometer
int ledSensorTHROTTLE = map(sensorReadingTHROTTLE, 0 , 1023, 0, ledBarCountGREEN); // map the result to a range from 0 to the number of LEDs for TROTTLE bar
for (int thisBarLedRED = 0; thisBarLedRED < ledBarCountRED; thisBarLedRED++) { // loop over the LED array for RED
if (thisBarLedRED < ledSensorBRAKE) {digitalWrite(ledBarPinsRED[thisBarLedRED], HIGH);} // if the array element's index is less than ledSensorBRAKE turn the pin for this element on
else {digitalWrite(ledBarPinsRED[thisBarLedRED], LOW);}} // turn off all pins higher than the ledSensorBRAKE
for (int thisBarLedGREEN = 0; thisBarLedGREEN < ledBarCountGREEN; thisBarLedGREEN++) { // loop over the LED array for GREEN
if (thisBarLedGREEN < ledSensorTHROTTLE) {digitalWrite(ledBarPinsGREEN[thisBarLedGREEN], HIGH);} // if the array element's index is less than ledSensorTHROTTLE turn the pin for this element on
else {digitalWrite(ledBarPinsGREEN[thisBarLedGREEN], LOW);}} // turn off all pins higher than the ledSensorTHROTTLE
}