Arduino Winrotor plus

 


#include <LiquidCrystal.h>
//Original pin numbers
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);


int AzSensor = 0; // Azimuth analog sensor
int ElSensor = 0; // Elevation analog sensor

int LEFT = 7; //port D7
int RIGHT = 6; //port D6
int UP = 8; //port D8
int DOWN = 9; //port D9


String inputString = ""; // a String to hold incoming data
boolean stringComplete = false; // whether the string is complete


void setup() {
 // put your setup code here, to run once:
 
 // initialize digital pin LED_BUILTIN as an output.
 pinMode(LED_BUILTIN, OUTPUT);
 
 pinMode(LEFT, OUTPUT);
 pinMode(RIGHT, OUTPUT);
 pinMode(UP, OUTPUT);
 pinMode(DOWN, OUTPUT);
 lcd.begin(16, 2);
 lcd.setCursor(0 ,0);
 lcd.print("PE1ASH ");

 // start serial port at 9600 bps and wait for port to open:
 Serial.begin(9600);
 inputString.reserve(200);

}

void loop() {
 // put your main code here, to run repeatedly:
 AzSensor = analogRead(A0);
 // read second analog input:
 ElSensor = analogRead(A1);
 // send sensor values:
 //Azimuth A001
 Serial.print(F("A"));
 Serial.println(AzSensor);
 //Elevation E01
 Serial.print(F("E"));
 Serial.println(ElSensor);
 lcd.setCursor(0 ,1);
 lcd.print("A" + String(AzSensor)+ " ");
 lcd.setCursor(8 ,1);
 lcd.print("E" + String(ElSensor) + " ");
 delay(200);
 // execute string command from app when a winrotor code arrives:
 if (stringComplete) {

 lcd.setCursor(8 ,0);
 //lcd.print(inputString + " ");

 if (inputString == "xs") {
 //zet port all down
 //STOP
 lcd.print("STOP ");
 digitalWrite(LEFT,LOW);
 digitalWrite(RIGHT,LOW);
 digitalWrite(UP,LOW);
 digitalWrite(DOWN,LOW);
 }
 if (inputString == "4a") {
 //zet port Right up
 lcd.print("RIGHT");
 digitalWrite(RIGHT,HIGH);
 }
 if (inputString== "2c") {
 //zet port left up
 lcd.print("LEFT ");
 digitalWrite(LEFT,HIGH);
 }
 if (inputString == "6d") {
 //zet port Up up
 lcd.print("UP ");
 digitalWrite(UP,HIGH);
 }
 if (inputString == "5e") {
 //zet port down up
 lcd.print("DOWN ");
 digitalWrite(DOWN,HIGH);
 }
 if (inputString == "tmnss") {
 //Set rotor Speed to 1
 lcd.print("SPEED1");
 //TODO
 }
 if (inputString == "snnn") {
 //Set rotor Speed to 2
 lcd.print("SPEED2");
 //TODO
 }
 if (inputString == "nmmm") {
 //Set rotor Speed to 3
 lcd.print("SPEED3");
 //TODO
 }
 if (inputString== "mttt") {
 //Set rotor Speed to 4
 lcd.print("SPEED4");
 //TODO
 }
 
 // clear the string:
 inputString = "";
 stringComplete = false;
 }
}

void serialEvent() {
 while (Serial.available()) {
 // get the new byte:
 char inChar = (char)Serial.read();
 // add it to the inputString:
 inputString += inChar;
 // if the incoming character is a newline, set a flag so the main loop can
 // do something about it:
 if (inputString.length() == 2) {
 if (inputString=="xs"||inputString=="4a"||inputString=="2c"||inputString=="6d"||inputString=="5e"||inputString=="tm"||inputString=="sn"||inputString=="nm"||inputString=="mt"){
 stringComplete = true;
 }
 if (inputString=="tm"||inputString=="sn"||inputString=="nm"||inputString=="mt"){
 //do nothing
 }
 // else{
 // inputString = "";
 // }
 }
 if (inputString.length() == 4) {
 if (inputString=="tmnss"||inputString=="snnn"||inputString=="nmmm"||inputString=="mttt"){
 stringComplete = true;
 }
 }
 }
}