I have modded a cheap drone controller to output its joystick values to an Arduino Nano.
I made it to output its 4 pot values using I2C to another Arduino don't ask why. So my problem is that I need to send 4 values but I can send only 1. Help me please.
I don't have a time limit or something so I don't need this quick or now!
I am also using a 16x2 LCD without I2C to show the live values and sometime I want to make a menu there or stuff like that.
I would like if you wrote the code for me but its ok if you cant. Also I'm kind of a noob at arduino programming.
Master(a.k.a the nano in the controller):
int pot1 = A0;
int pot2 = A1;
int pot3 = A2;
int pot4 = A3;
int potValue1 = 0;
int potValue2 = 0;
int potValue3 = 0;
int potValue4 = 0;
int led = 10;
int button = 8;
int lastButtonState; // the previous state of button
int currentButtonState; // the current state of button
int output1 = A4;
int output2 = A5;
int output3 = A6;
int output4 = A7;
#include <Wire.h>
#include <LiquidCrystal.h> // includes the LiquidCrystal Library
LiquidCrystal lcd(2, 3, 4, 5, 6, 7); // Creates an LC object. Parameters: (rs, enable, d4, d5, d6, d7)
#define SLAVE_ADDR 9
void setup() {
pinMode(led, OUTPUT);
pinMode(button, INPUT_PULLUP);
// Open serial communications and wait for port to open:
Wire.begin();
lcd.begin(16, 2);
lcd.print(" ArduinoTX");
digitalWrite(led, HIGH);
delay(600);
digitalWrite(led, LOW);
delay(600);
digitalWrite(led, HIGH);
delay(600);
digitalWrite(led, LOW);
delay(600);
digitalWrite(led, HIGH);
delay(600);
delay(3000);
lcd.clear();
}
void loop() {
currentButtonState = digitalRead(button);
potValue1 = analogRead(pot1);
potValue2 = analogRead(pot2);
potValue3 = analogRead(pot3);
potValue4 = analogRead(pot4);
int sendValue = map(potValue4, 1, 1023, 1, 255); //converting to values 255 max
int sendValue2 = map(potValue3, 1, 1023, 1, 255);
int sendValue3 = map(potValue2, 1, 1023, 1, 255);
int sendValue4 = map(potValue1, 1, 1023, 1, 255);
Wire.beginTransmission(SLAVE_ADDR); //sending only one pot value
Wire.write(sendValue);
Wire.endTransmission();
lastButtonState = currentButtonState; // save the last state
currentButtonState = digitalRead(button); // read new state
if (lastButtonState == LOW && currentButtonState == LOW) { //dont worry about this
lcd.print(potValue4);
lcd.print(" ");
lcd.print(potValue2);
delay(delayTime);
lcd.clear();
lcd.setCursor(0, 2);
lcd.print(potValue3);
lcd.print(" ");
lcd.print(potValue1);
delay(delayTime);
lcd.clear();
}
}
Slave(or an uno who receives the values):
int rd;
int br;
#include <Wire.h>
#define SLAVE_ADDR 9
void setup() {
// put your setup code here, to run once:
Wire.begin(SLAVE_ADDR);
// Function to run when data received from master
Wire.onReceive(receiveEvent);
// Setup Serial Monitor
Serial.begin(9600);
}
void receiveEvent() {
// read one character from the I2C
rd = Wire.read();
Serial.println(rd);
}
void loop() {
delay(50);
}
Thanks!