Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unsigned int data_pres = 0;
- unsigned int avg = 0;
- #include <movingAvg.h>
- movingAvg avgPres(20);
- #include <SoftwareSerial.h>
- SoftwareSerial nexSerial(3, 2); // RX, TX
- void setup() {
- Serial.begin(9600);
- nexSerial.begin(9600);
- pinMode(A0, INPUT);
- avgPres.begin();
- delay(1000);
- }
- void loop() {
- //data_pres = map(analogRead(A0),0,1024,0,255); //Read the pot value ann map it to 0.255 (max value of waveform=255)
- tampil_text("t0", "Press(psi)");
- tampil_text("t1", "-3");
- tampil_text("t2", "-2");
- tampil_text("t3", "-1");
- tampil_text("t4", "0");
- tampil_text("t5", "1");
- tampil_text("t6", "");
- int dt_adc = analogRead(A0);
- data_pres = dt_adc*4; // scaling pressure graph
- avg = avgPres.reading(dt_adc);
- float voltage = (avg*5.0)/1024.0;
- float pressure_pascal = (3.0*((float)voltage-0.475))*1000000.0; //calibrate here
- float pressure_bar = pressure_pascal/10e5;
- float pressure_psi = pressure_bar*14.5038;
- pressure_psi = pressure_psi - 1;
- Serial.println(pressure_psi);
- String Tosend = "add ";
- Tosend += 1;
- Tosend += ",";
- Tosend += 0;
- Tosend += ",";
- Tosend += data_pres;
- nexSerial.print(Tosend);
- nexSerial.write(0xff);
- nexSerial.write(0xff);
- nexSerial.write(0xff);
- delay(5);
- }
- void tampil_text(String _add_txt, String _txt_display) {
- String buf_txt = _add_txt + ".txt=" + "\"" + _txt_display + "\"";
- nexSerial.print(buf_txt);
- nexSerial.write(0xff);
- nexSerial.write(0xff);
- nexSerial.write(0xff);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement