String comdata = "";
int numdata[6] = {0}, PWMPin[6] = {3, 5, 6, 9, 10, 11}, mark = 0;
void setup()
{
for(int i = 0; i < 6; i++) pinMode(PWMPin[i], OUTPUT);
Serial.begin(9600);
}
void loop()
{
int j = 0;
while (Serial.available() > 0)
{
comdata += char(Serial.read());
delay(2);
mark = 1;
}
if(mark == 1)
{
Serial.println(comdata);
Serial.println(comdata.length());
for(int i = 0; i < comdata.length() ; i++)
{
if(comdata[i] == ',')
{
j++;
}
else
{
numdata[j] = numdata[j] * 10 + (comdata[i] - '0');
}
}
comdata = String("");
for(int i = 0; i < 6; i++)
{
Serial.print("Pin ");
Serial.print(PWMPin[i]);
Serial.print(" = ");
Serial.println(numdata[i]);
analogWrite(PWMPin[i], numdata[i]);
numdata[i] = 0;
}
mark = 0;
}
}
For the use of the Arduino serial port part, it is somewhat inconvenient. Although the function to be called is officially provided, it is not flexible enough. The following is a summary of the string...
This blog takes the use of the 4G dtu network box in the human network as an example...
Receive serial port UDP sends...
Arduino serial character conversion When doing Bluetooth acceptance experiments, the Arduino serial port receives all character data. Sometimes we want to perform operations on the data received by th...
Enter a, send humidity, enter b, send temperature...
Torting a morning, finally figured out the difference between serial.write and serial.print, the former is transferred between machines, the latter is to view, so transmitting characters....
Arduino data type serial port printout I chose the ESP8266 development board, NodeMCU 1.0, print test: Corresponding output: 19:45:42.135 -> 9999 19:45:43.615 -> 65535 19:45:45.136 -> 88888 1...
One example in "Love in Arduino" is to communicate with Arduino with the Processing program. The code is generally as follows, after modification: Still don't drive processing, try node I wa...
Write with nano development board...
1. We can send data to the computer through the Arduino for observation through the serial monitor. 2. You can call functionsSerial.available()To determine whether data is sent over, thereby receiving...