int potentiometer_pin = A0; //Define the analog input pin
int potentiometer_pin1 = A1; //Define the analog input pin
int potentiometer_pin2 = A2; //Define the analog input pin
int potentiometer_pin3 = A3; //Define the analog input pin
const int buttonPin = 8; // the number of the pushbutton pin
// variables will change:
int buttonState = 0; // variable for reading the pushbutton status
void setup() {
Serial.begin(9600); //Default baud rate of the Nextion TFT is 9600
pinMode(potentiometer_pin, INPUT); //Define pin as input
pinMode(potentiometer_pin1, INPUT); //Define pin as input
pinMode(potentiometer_pin2, INPUT); //Define pin as input
pinMode(potentiometer_pin3, INPUT); //Define pin as input
pinMode(buttonPin, INPUT);
}
void loop() {
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
if (buttonState == HIGH) {
routine0();
routine1();
routine2();
routine3();
}
}
void routine0() {
int Value = map(analogRead(potentiometer_pin), 0, 1024, 0, 200); //Read the pot value ann map it to 0.255 (max value of waveform=255)
String Tosend = "add "; //We send the string "add "
Tosend += 1; //send the id of the block you want to add the value to
Tosend += ",";
Tosend += 0; //Channel of taht id, in this case channel 0 of the waveform
Tosend += ",";
Tosend += Value; //Send the value and 3 full bytes
//Send the value and 3 full bytes
Serial.print(Tosend);
Serial.write(0xff);
Serial.write(0xff);
Serial.write(0xff);
}
void routine1() {
int Value1 = map(analogRead(potentiometer_pin1), 0, 1024, 0, 200); //Read the pot value ann map it to 0.255 (max value of waveform=255)
String Tosend = "add "; //We send the string "add "
Tosend += 1; //send the id of the block you want to add the value to
Tosend += ",";
Tosend += 1; //Channel of taht id, in this case channel 0 of the waveform
Tosend += ",";
Tosend += (Value1 + 10);
//Send the value and 3 full bytes
Serial.print(Tosend);
Serial.write(0xff);
Serial.write(0xff);
Serial.write(0xff);
}
void routine2() {
int Value = map(analogRead(potentiometer_pin2), 0, 1024, 0, 200); //Read the pot value ann map it to 0.255 (max value of waveform=255)
String Tosend = "add "; //We send the string "add "
Tosend += 1; //send the id of the block you want to add the value to
Tosend += ",";
Tosend += 2; //Channel of taht id, in this case channel 0 of the waveform
Tosend += ",";
Tosend += (Value + 20); //Send the value and 3 full bytes
//Send the value and 3 full bytes
Serial.print(Tosend);
Serial.write(0xff);
Serial.write(0xff);
Serial.write(0xff);
}
void routine3() {
int Value1 = map(analogRead(potentiometer_pin3), 0, 1024, 0, 200); //Read the pot value ann map it to 0.255 (max value of waveform=255)
String Tosend = "add "; //We send the string "add "
Tosend += 1; //send the id of the block you want to add the value to
Tosend += ",";
Tosend += 3; //Channel of taht id, in this case channel 0 of the waveform
Tosend += ",";
Tosend += (Value1 + 30);
//Send the value and 3 full bytes
Serial.print(Tosend);
Serial.write(0xff);
Serial.write(0xff);
Serial.write(0xff);
}
Comments