|
|
Ligne 17 : |
Ligne 17 : |
| <nowiki> | | <nowiki> |
| [[Category:Projet]] | | [[Category:Projet]] |
| String Msg;
| |
| char ChNumbers = 1; // Number of enabled channels
| |
| char ChScanning = 0; // Channel to scan
| |
|
| |
| int ChValues[4] = {0,0,0,0}; // Array of channel values
| |
| long LastMeasTime = 0; // Time of last measurement
| |
|
| |
| void setup() {
| |
|
| |
| pinMode(13, OUTPUT);
| |
| Serial.begin(57600); // Initialise serial
| |
| delay(3000); // Let's the module start
| |
| Serial.println(""); // Dismiss partial sent messages
| |
| Serial.println("$PING 200"); // Enable real-time communication
| |
| SendSplashScreen(); // Send Application Splash Screen
| |
|
| |
| }
| |
|
| |
| void SendSplashScreen() // Send the splash screen cointaining the Start button
| |
| {
| |
| Serial.print("\n$P:D!g5;{^*30%80,100!g3{ht2,000,1*7T#180:μPanel;}/3{*4T#888:Mobile Interactive;_T#888:Universal Panel;}");
| |
| Serial.println("_{*10T#FFF:Podometre Testeur;_*8T#3AA:P.Pinault BIOZOPIX;_I1.762%50;}}/20*10B0%20,10r30g0.1#FFFfb:PODO;");
| |
| Serial.println(""); // Terminate the panel definition
| |
|
| |
| }
| |
|
| |
| void SendPanel(char NumberOfChannels)
| |
| {
| |
| char x;
| |
| char y;
| |
| // Send the definition of the Panel header and define the macro to display channels
| |
| Serial.print("$P:D!g1;{^%100,20!g8|%33B1%80:FSR+;|%33B2%80:FSR-;|%33B3%80:Sortie;}");
| |
| Serial.print("K1:{p8*15%87!g8_T:FSR?= ;M??fb:0.00;T: N;A??G%45:5.10:5.11:0::0:0.25;|T:BIOZOPIX;}$");
| |
|
| |
| for(x=0; x<NumberOfChannels; x++) // Recall the channel Macro to display enabled channel sub-panel
| |
| {
| |
| Serial.print("J1("); // Macro call keyword
| |
| Serial.print(x,DEC); // Pass to the macro the number of channel
| |
| // Serial.print(y,DEC); // Pass to the macro the number of channel
| |
| Serial.print(")"); // Terminate the Macro call
| |
| }
| |
|
| |
| Serial.println(""); // Terminate the panel definition
| |
|
| |
| for(x=0; x<NumberOfChannels; x++) DisplayChannel(x); // Update the channels' value
| |
|
| |
| }
| |
|
| |
| void DisplayChannel(char c) // Update the channel value
| |
| {
| |
|
| |
| Serial.print("#A"); Serial.print(c,DEC); Serial.print(":"); // Update the analog bar value
| |
| Serial.println(ChValues[c]); // with the acquired value (LSB)
| |
|
| |
| // float v = ((float) ChValues[c]) / 1024.0 * 5.0; // Transfor the LSB into voltage
| |
| float w = ((float) ChValues[c]) / 1024.0 * 5.0*300/2.65;
| |
| // Serial.print("#M"); Serial.print(c,DEC); // Update the channel value message
| |
| analogWrite(13, int(w/2));
| |
| // Serial.println(v); // with the acquired value (V)
| |
| Serial.print("#M"); Serial.print(c,DEC); // Update the channel value message
| |
| Serial.println(w); // with the acquired value (V)
| |
|
| |
| }
| |
|
| |
|
| |
| void loop() {
| |
|
| |
| int c;
| |
| while ((c = Serial.read()) > '\n') Msg += (char) c; // Read incoming chars, if any, until new line
| |
| if (c == '\n') // is message complete?
| |
| {
| |
|
| |
| if (Msg.substring(0,4).equals("#B3P")) SendSplashScreen(); // has Exit key been pressed? Splash screen!
| |
| if (Msg.substring(0,4).equals("#B0P")) SendPanel(ChNumbers); // has Start key been pressed? Display Panel
| |
|
| |
| if (Msg.substring(0,4).equals("#B1P")) // has the channel ADD button been pressed?
| |
| {
| |
| ChNumbers++; // Increase the number of channels
| |
| if (ChNumbers > 4) ChNumbers = 4; // up to 4
| |
| SendPanel(ChNumbers); // Send the new panel
| |
| }
| |
|
| |
| if (Msg.substring(0,4).equals("#B2P")) // has the channel DELETE button been pressed?
| |
| {
| |
| ChNumbers--; // Decrease the number of channels
| |
| if (ChNumbers < 1) ChNumbers = 1; // down to 1
| |
| SendPanel(ChNumbers); // Send the new panel
| |
| }
| |
|
| |
| Msg = "";
| |
| }
| |
|
| |
| if (millis() - LastMeasTime > 100) // is time for a new measurement?
| |
| {
| |
| if (ChScanning >= ChNumbers) ChScanning = 0; // if all channels already scanned, restart from 0
| |
| ChValues[ChScanning] = analogRead(A0+ChScanning); // Read analog value of selected channel
| |
| DisplayChannel(ChScanning++); // Update panel and move to the next channel
| |
| LastMeasTime = millis(); // save the time of this measurement
| |
| }
| |
|
| |
|
| |
| delay(150);
| |
| Serial.println(""); // Terminate the panel definition
| |
|
| |
|
| |
| }
| |
| ]]
| |
| </nowiki> | | </nowiki> |