Hello,
I am rather new to coding Arduinos, and I am trying to create a controller for an RC airplane that I am building (which also uses an Arduino). I am using HC-12 Transceiver modules for communication, and I was wondering what code I have to use to send an array of data through the transceiver.
My basic idea is that I read in the values from 2 joysticks (X,Y, and a button for each), put it into an array, and then send it through to the other HC-12 module. I then want to receive data from the sensors I will be putting on the airplane, which I can then display on my LCD screen.
What would be the best way to send/receive the data through the HC-12? I'm having trouble with the code.
My controller code looks something like this (it's mainly pseudocode right now):
/*************************
* Tasks
************************/
//1. Read in all joystick values
//2. Arrange joystick values as an array
//3. Send Joystick Array through HC-12 Module
//4. Receive Temperature/Pressure from HC-12 module
//5. Convert Pressure to Altitude
//6. Display Pressure and Temperature on LCD screen
//Setup for Joysticks
#define LJX A0
#define LJY A1
#define RJX A2
#define RJY A3
#define LJB 2
#define RJB 3
//setup for HC-12 Tranceiver Module
#include <SoftwareSerial.h>
SoftwareSerial HC12(12,13); //TX and RX pins for the HC-12 Module
//setup for I2C LCD screen
#include <LiquidCrystal_I2C.h>
void setup() {
// put your setup code here, to run once:
//joystick setup
pinMode(LJX,INPUT);
pinMode(LJY,INPUT);
pinMode(RJX,INPUT);
pinMode(RJY,INPUT);
pinMode(LJB,INPUT_PULLUP);
pinMode(RJB,INPUT_PULLUP);
//HC-12 Setup
HC12.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
//1.//
int LX = analogRead(LJX);
int LY = analogRead(LJY);
int RX = analogRead(RJX);
int RY = analogRead(RJY);
int LB = digitalRead(LJB);
int RB = digitalRead(RJB);
//2.//
int Joysticks[] = {LX,LY,RX,RY,LB,RB};
//3.//
HC12.write(Joysticks); // does this work for the code or do I need to do something else for it?
//and more after this. see "tasks" at the beginning for what comes after this.
}