1
2
3
4
5
6
7#include <SoftwareSerial.h>
8#define SerialIn 2
9#define SerialOut 7
10#define wDelay 900
11int inPin = 5;
12int val = 0;
13SoftwareSerial mySerialPort(SerialIn, SerialOut);
14void setup()
15
16{
17 pinMode(SerialOut, OUTPUT);
18 pinMode(SerialIn, INPUT);
19 mySerialPort.begin(19200);
20 mySerialPort.print("vv");
21 mySerialPort.print("xxxx");
22 delay(wDelay);
23 mySerialPort.print("----");
24 delay(wDelay);
25 mySerialPort.print("8888");
26 delay(wDelay);
27 mySerialPort.print("xxxx");
28 delay(wDelay);
29 Serial.begin(9600);
30}
31void loop()
32{
33 val = analogRead(inPin);
34 Serial.println(val);
35 dispData(val);
36 val = map(val, 1, 100, 1, 2048);
37 tone(3,val,10);
38}
39void dispData(int i)
40{
41 if ((i<-999) || (i>9999))
42 {
43 mySerialPort.print("ERRx");
44 return;
45 }
46 char fourChars[5];
47 sprintf(fourChars, "%04d", i);
48 mySerialPort.print("v");
49 mySerialPort.print(fourChars);
50}
51