Components and supplies
1
Jumper wires (generic)
1
Nextion NX4024T032 - Generic 3.2" HMI TFT Intelligent LCD Touch Display Module
1
Arduino UNO
Project description
Code
The code for the project
arduino
Here's the code for the Uno
1int potentiometer_pin = A0; //Define the analog input pin 2int potentiometer_pin1 = A1; //Define the analog input pin 3int potentiometer_pin2 = A2; //Define the analog input pin 4int potentiometer_pin3 = A3; //Define the analog input pin 5const int buttonPin = 8; // the number of the pushbutton pin 6// variables will change: 7int buttonState = 0; // variable for reading the pushbutton status 8 9void setup() { 10 Serial.begin(9600); //Default baud rate of the Nextion TFT is 9600 11 pinMode(potentiometer_pin, INPUT); //Define pin as input 12 pinMode(potentiometer_pin1, INPUT); //Define pin as input 13 pinMode(potentiometer_pin2, INPUT); //Define pin as input 14 pinMode(potentiometer_pin3, INPUT); //Define pin as input 15 pinMode(buttonPin, INPUT); 16} 17 18void loop() { 19 // read the state of the pushbutton value: 20 buttonState = digitalRead(buttonPin); 21 if (buttonState == HIGH) { 22 routine0(); 23 routine1(); 24 routine2(); 25 routine3(); 26 } 27 28} 29 30void routine0() { 31 32 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) 33 String Tosend = "add "; //We send the string "add " 34 Tosend += 1; //send the id of the block you want to add the value to 35 Tosend += ","; 36 Tosend += 0; //Channel of taht id, in this case channel 0 of the waveform 37 Tosend += ","; 38 Tosend += Value; //Send the value and 3 full bytes 39 //Send the value and 3 full bytes 40 Serial.print(Tosend); 41 Serial.write(0xff); 42 Serial.write(0xff); 43 Serial.write(0xff); 44} 45 46void routine1() { 47 48 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) 49 String Tosend = "add "; //We send the string "add " 50 Tosend += 1; //send the id of the block you want to add the value to 51 Tosend += ","; 52 Tosend += 1; //Channel of taht id, in this case channel 0 of the waveform 53 Tosend += ","; 54 Tosend += (Value1 + 10); 55 //Send the value and 3 full bytes 56 Serial.print(Tosend); 57 Serial.write(0xff); 58 Serial.write(0xff); 59 Serial.write(0xff); 60 61} 62 63void routine2() { 64 65 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) 66 String Tosend = "add "; //We send the string "add " 67 Tosend += 1; //send the id of the block you want to add the value to 68 Tosend += ","; 69 Tosend += 2; //Channel of taht id, in this case channel 0 of the waveform 70 Tosend += ","; 71 Tosend += (Value + 20); //Send the value and 3 full bytes 72 //Send the value and 3 full bytes 73 Serial.print(Tosend); 74 Serial.write(0xff); 75 Serial.write(0xff); 76 Serial.write(0xff); 77} 78 79void routine3() { 80 81 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) 82 String Tosend = "add "; //We send the string "add " 83 Tosend += 1; //send the id of the block you want to add the value to 84 Tosend += ","; 85 Tosend += 3; //Channel of taht id, in this case channel 0 of the waveform 86 Tosend += ","; 87 Tosend += (Value1 + 30); 88 //Send the value and 3 full bytes 89 Serial.print(Tosend); 90 Serial.write(0xff); 91 Serial.write(0xff); 92 Serial.write(0xff); 93 94} 95 96
The code for the project
arduino
Here's the code for the Uno
1int potentiometer_pin = A0; //Define 2 the analog input pin 3int potentiometer_pin1 = A1; //Define 4 the analog input pin 5int potentiometer_pin2 = A2; //Define 6 the analog input pin 7int potentiometer_pin3 = A3; //Define 8 the analog input pin 9const int buttonPin = 8; // the number of the pushbutton 10 pin 11// variables will change: 12int buttonState = 0; // variable for 13 reading the pushbutton status 14 15void setup() { 16 Serial.begin(9600); //Default 17 baud rate of the Nextion TFT is 9600 18 pinMode(potentiometer_pin, INPUT); //Define 19 pin as input 20 pinMode(potentiometer_pin1, INPUT); //Define 21 pin as input 22 pinMode(potentiometer_pin2, INPUT); //Define 23 pin as input 24 pinMode(potentiometer_pin3, INPUT); //Define 25 pin as input 26 pinMode(buttonPin, INPUT); 27} 28 29void loop() { 30 // read 31 the state of the pushbutton value: 32 buttonState = digitalRead(buttonPin); 33 34 if (buttonState == HIGH) { 35 routine0(); 36 routine1(); 37 routine2(); 38 39 routine3(); 40 } 41 42} 43 44void routine0() { 45 46 int Value = map(analogRead(potentiometer_pin), 47 0, 1024, 0, 200); //Read the pot value ann map it to 0.255 (max value of waveform=255) 48 49 String Tosend = "add "; //We send the 50 string "add " 51 Tosend += 1; //send 52 the id of the block you want to add the value to 53 Tosend += ","; 54 Tosend 55 += 0; //Channel of taht id, in 56 this case channel 0 of the waveform 57 Tosend += ","; 58 Tosend += Value; 59 //Send the value and 3 full bytes 60 61 //Send the value and 3 full bytes 62 Serial.print(Tosend); 63 Serial.write(0xff); 64 65 Serial.write(0xff); 66 Serial.write(0xff); 67} 68 69void routine1() { 70 71 72 int Value1 = map(analogRead(potentiometer_pin1), 0, 1024, 0, 200); //Read the 73 pot value ann map it to 0.255 (max value of waveform=255) 74 String Tosend = "add 75 "; //We send the string "add " 76 Tosend 77 += 1; //send the id of the block 78 you want to add the value to 79 Tosend += ","; 80 Tosend += 1; //Channel 81 of taht id, in this case channel 0 of the waveform 82 Tosend += ","; 83 Tosend 84 += (Value1 + 10); 85 //Send the value and 3 full bytes 86 Serial.print(Tosend); 87 88 Serial.write(0xff); 89 Serial.write(0xff); 90 Serial.write(0xff); 91 92} 93 94void 95 routine2() { 96 97 int Value = map(analogRead(potentiometer_pin2), 0, 1024, 98 0, 200); //Read the pot value ann map it to 0.255 (max value of waveform=255) 99 100 String Tosend = "add "; //We send the 101 string "add " 102 Tosend += 1; //send 103 the id of the block you want to add the value to 104 Tosend += ","; 105 Tosend 106 += 2; //Channel of taht id, in 107 this case channel 0 of the waveform 108 Tosend += ","; 109 Tosend += (Value 110 + 20); //Send the value and 3 full bytes 111 112 //Send the value and 3 full bytes 113 Serial.print(Tosend); 114 Serial.write(0xff); 115 116 Serial.write(0xff); 117 Serial.write(0xff); 118} 119 120void routine3() { 121 122 123 int Value1 = map(analogRead(potentiometer_pin3), 0, 1024, 0, 200); //Read the 124 pot value ann map it to 0.255 (max value of waveform=255) 125 String Tosend = "add 126 "; //We send the string "add " 127 Tosend 128 += 1; //send the id of the block 129 you want to add the value to 130 Tosend += ","; 131 Tosend += 3; //Channel 132 of taht id, in this case channel 0 of the waveform 133 Tosend += ","; 134 Tosend 135 += (Value1 + 30); 136 //Send the value and 3 full bytes 137 Serial.print(Tosend); 138 139 Serial.write(0xff); 140 Serial.write(0xff); 141 Serial.write(0xff); 142 143} 144 145
Hmi project
Copy to micro sd card and load onto screen
Downloadable files
Image of wiring
Minimal wiring is required for this scope
Image of wiring
Image of wiring
Minimal wiring is required for this scope
Image of wiring
Comments
Only logged in users can leave comments