- ASCIITable(ASCII表格):使用Arduino的高等的串口輸出函數(shù)。
- 調(diào)光器:移動(dòng)鼠標(biāo)來(lái)改變LED燈的亮度
- 圖表:發(fā)送數(shù)據(jù)到電腦纹因,然后在Processing里畫出它的圖表。
- Midi(樂(lè)器數(shù)字接口):連續(xù)發(fā)送MIDI音符信息
- 多串口Mega:使能Arduino Mega上2個(gè)串口爽彤。
- 物理像素:通過(guò)從Processing或者M(jìn)ax/MSP發(fā)送數(shù)據(jù)到Arduino上剩胁,使LED開關(guān)。
- 讀取ASCII字符串:分析整數(shù)里一個(gè)用逗號(hào)分隔的字符串袱巨,來(lái)使一個(gè)LED燈褪色阁谆。
- 串口呼叫響應(yīng):通過(guò)一個(gè)呼-應(yīng)的方法(握手)來(lái)發(fā)送多個(gè)變數(shù)
- 串口呼叫響應(yīng)ASCII:通過(guò)一個(gè)呼-應(yīng)的方法(握手)來(lái)發(fā)送多個(gè)變數(shù),并在發(fā)送前解碼(ASCII)這些數(shù)值愉老。
- Serial Event:使用SerialEvent()函數(shù)
- 可視顏色混合器:從Arduino發(fā)送多個(gè)變數(shù)到你的電腦场绿,然后在Processing或者M(jìn)ax/MSP上讀取這些數(shù)據(jù)
ASCIITable(ASCII表格)
這個(gè)例子示范了領(lǐng)先的串口打印函數(shù),在串口監(jiān)視器產(chǎn)生字符表格和它們?cè)赿ecimal嫉入,hexadecimal, octal, 和 binary的ASCII值焰盗。更多關(guān)于ASCII,請(qǐng)參考http://www.asciitable.com//en.wikipedia.org/wiki/ASCII
無(wú)其他要求咒林,只要開發(fā)板通過(guò)串口或者USB口連接到電腦熬拒。
示例代碼:
程序等待setup()函數(shù)的串口連接,然后一行一行打印ASCII表格直至最后一個(gè)字符垫竞。當(dāng)完成這個(gè)步驟澎粟,如果沒有其他事,它會(huì)進(jìn)入無(wú)止盡的循環(huán)件甥。關(guān)閉和打開串口監(jiān)視窗口將會(huì)使開發(fā)板復(fù)位捌议,從而使程序重新開始運(yùn)行。
void setup() {
//Initialize serial and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
// prints title with ending line break
Serial.println("ASCII Table ~ Character Map");
}
// first visible ASCIIcharacter '!' is number 33:
int thisByte = 33;
// you can also write ASCII characters in single quotes.
// for example, '!' is the same as 33, so you could also use this:
// int thisByte = '!';
void loop() {
// prints value unaltered, i.e. the raw binary version of the byte.
// The Serial Monitor interprets all bytes as ASCII, so 33, the first number,
// will show up as '!'
Serial.write(thisByte);
Serial.print(", dec: ");
// prints value as string as an ASCII-encoded decimal (base 10).
// Decimal is the default format for Serial.print() and Serial.println(),
// so no modifier is needed:
Serial.print(thisByte);
// But you can declare the modifier for decimal if you want to.
// this also works if you uncomment it:
// Serial.print(thisByte, DEC);
Serial.print(", hex: ");
// prints value as string in hexadecimal (base 16):
Serial.print(thisByte, HEX);
Serial.print(", oct: ");
// prints value as string in octal (base 8);
Serial.print(thisByte, OCT);
Serial.print(", bin: ");
// prints value as string in binary (base 2) also prints ending line break:
Serial.println(thisByte, BIN);
// if printed last visible character '~' or 126, stop:
if (thisByte == 126) { // you could also use if (thisByte == '~') {
// This loop loops forever and does nothing
while (true) {
continue;
}
}
// go on to the next character
thisByte++;
}
調(diào)光器
這個(gè)例子展示怎么從個(gè)人電腦發(fā)送數(shù)據(jù)到Arduino或者Genuino開發(fā)板來(lái)控制LED的亮度引有。這個(gè)數(shù)據(jù)是用特定的字節(jié)發(fā)送瓣颅,每個(gè)數(shù)據(jù)的范圍從0-255.程序讀取三個(gè)字節(jié),并且用它來(lái)設(shè)置LED的亮度譬正。
你可以從任何可以接入電腦串口的軟件發(fā)送字節(jié)到開發(fā)板宫补。
LED燈串聯(lián)一個(gè)220 ohm限流電阻檬姥,再連接到數(shù)字引腳pin9。LED的長(zhǎng)腿(正極或者陽(yáng)極)應(yīng)該連到電阻的輸出端粉怕,而短腿(負(fù)極或者陰極)連接到地健民。
const int ledPin = 9; // the pin that the LED is attached to
void setup() {
// initialize the serial communication:
Serial.begin(9600);
// initialize the ledPin as an output:
pinMode(ledPin, OUTPUT);
}
void loop() {
byte brightness;
// check if data has been sent from the computer:
if (Serial.available()) {
// read the most recent byte (which will be from 0 to 255):
brightness = Serial.read();
// set the brightness of the LED:
analogWrite(ledPin, brightness);
}
}
官網(wǎng)的這個(gè)例程可能效果病不十分顯著。
圖表
這個(gè)例子展示怎么從Arduino或者Genuino發(fā)送字節(jié)數(shù)據(jù)到個(gè)人電腦贫贝,并用圖表繪制結(jié)果秉犹。這個(gè)叫串口通訊,因?yàn)殚_發(fā)板和電腦似乎通過(guò)串口連接稚晚,即使它實(shí)際用USB接口崇堵,一個(gè)串口-USB和一個(gè)USB-串口轉(zhuǎn)換器。
你可以用Arduino IDE的串口監(jiān)視器來(lái)觀察發(fā)送的數(shù)據(jù)客燕,或者它可以通過(guò) Processing (看下面的代碼), Flash, PD, Max/MSP等讀取鸳劳。
連接電位計(jì)或者其他模擬傳感器到模擬輸入引腳A0
用上面代碼例子里的Processing程序,你可以獲得一個(gè)傳感值圖表也搓。隨著你改變傳感器的值赏廓,你會(huì)獲得像下面那樣的東西:
const int lowestPin = 2;
const int highestPin = 13;
void setup() {
// set pins 2 through 13 as outputs:
for (int thisPin = lowestPin; thisPin <= highestPin; thisPin++) {
pinMode(thisPin, OUTPUT);
}
}
void loop() {
// iterate over the pins:
for (int thisPin = lowestPin; thisPin <= highestPin; thisPin++) {
// fade the LED on thisPin from off to brightest:
for (int brightness = 0; brightness < 255; brightness++) {
analogWrite(thisPin, brightness);
delay(2);
}
// fade the LED on thisPin from brightest to off:
for (int brightness = 255; brightness >= 0; brightness--) {
analogWrite(thisPin, brightness);
delay(2);
}
// pause between LEDs:
delay(100);
}
}
Midi(樂(lè)器數(shù)字接口)
這個(gè)教程展示怎么從Arduino或者Genuino開發(fā)板通過(guò)一個(gè)5極DIN電纜來(lái)發(fā)送MIDI音符到一個(gè)MIDI樂(lè)器。
MIDI傍妒,樂(lè)器的數(shù)字接口幔摸,一個(gè)用于控制合成器,音序器拍顷,和其他音樂(lè)設(shè)備的協(xié)議抚太。MIDI設(shè)備通常分為兩大類:控制器(基于人的動(dòng)作來(lái)產(chǎn)生MIDI信號(hào)的設(shè)備)和合成器(包括采樣器,音序器等等)昔案。后者輸入MIDI數(shù)據(jù)尿贫,就會(huì)產(chǎn)生聲音,光踏揣,或者其他的東西庆亡。
MIDI使一個(gè)串口協(xié)議,可以每秒鐘操作31捞稿,250字節(jié)又谋。開發(fā)板的內(nèi)置串口接口(所有在Mega上的串口接口都一樣)可以在那個(gè)速率上發(fā)送數(shù)據(jù)。
MIDI字節(jié)被分成兩類型:命令字節(jié)和數(shù)據(jù)字節(jié)娱局。命令字節(jié)通常是大于128彰亥,或者0x80到0xFF(十六進(jìn)制)。數(shù)據(jù)字節(jié)通常少于127衰齐,或者0x00到0x7F(十六進(jìn)制)任斋。命令包括類似note on, note off, pitch bend等等。數(shù)據(jù)字節(jié)包括彈奏音符的音高耻涛,速率废酷,或者瘟檩,音符音量,彎音等等澈蟆。更多細(xì)節(jié)墨辛,查看MIDI特性或者MIDI Protocol Guides on the Web。
MIDI數(shù)據(jù)通常用十六進(jìn)制符號(hào)表示趴俘,因?yàn)镸IDI音階和樂(lè)器被分成16組睹簇。
根據(jù)MIDI說(shuō)明書,所有MIDI連接器都是母座寥闪。這里是怎樣把連接器連接到開發(fā)板带膀。
MIDI插座pin5通過(guò)220 ohm電阻連接到數(shù)字引腳pin1。
MIDI插座pin2連接到地橙垢。
MIDI插座pin4通過(guò)220 ohm電阻連接到+5V。
示例代碼:
注意:如果你用帶有ATmega3U4的開發(fā)板(如DUE或者Leonardo)伦糯,請(qǐng)根據(jù)下面程序用Serial1來(lái)替換Serial柜某。
void setup() {
// Set MIDI baud rate:
Serial.begin(31250);
}
void loop() {
// play notes from F#-0 (0x1E) to F#-5 (0x5A):
for (int note = 0x1E; note < 0x5A; note ++) {
//Note on channel 1 (0x90), some note value (note), middle velocity (0x45):
noteOn(0x90, note, 0x45);
delay(100);
//Note on channel 1 (0x90), some note value (note), silent velocity (0x00):
noteOn(0x90, note, 0x00);
delay(100);
}
}
// plays a MIDI note. Doesn't check to see that cmd is greater than 127, or that
// data values are less than 127:
void noteOn(int cmd, int pitch, int velocity) {
Serial.write(cmd);
Serial.write(pitch);
Serial.write(velocity);
}
多串口Mega
很多時(shí)候一個(gè)串口不夠用。當(dāng)嘗試和多個(gè)串口的設(shè)備通訊敛纲,同時(shí)發(fā)送數(shù)據(jù)回主串口窗口喂击,一些額外的RX/TX連接口就變成很受歡迎的了。這個(gè)例子充分地利用了Arduino和Genuino Mega的3個(gè)輔助串口接口淤翔,使任何輸入從連接器讀取的數(shù)據(jù)直接發(fā)送到到主TX線翰绊,然后,發(fā)送到主串口窗口供觀察旁壮。
檢查你選擇的串口設(shè)備的數(shù)據(jù)手冊(cè)后监嗜,確保電源和連線沒問(wèn)題。把你設(shè)備的RX pin和TX pin連接到你Mega開發(fā)板的TX1和RX1抡谐,如原理圖所示裁奇。
示例代碼:
確保你的Mega開發(fā)板通過(guò)USB連接到你的電腦,啟動(dòng)串口通訊麦撵。
void setup() {
// initialize both serial ports:
Serial.begin(9600);
Serial1.begin(9600);
}
void loop() {
// read from port 1, send to port 0:
if (Serial1.available()) {
int inByte = Serial1.read();
Serial.write(inByte);
}
// read from port 0, send to port 1:
if (Serial.available()) {
int inByte = Serial.read();
Serial1.write(inByte);
}
}
物理像素
這個(gè)例子示范了怎么用Arduino或者Genuino開發(fā)板來(lái)接受來(lái)自電腦的數(shù)據(jù)刽肠。當(dāng)接受到字符“H”時(shí),開發(fā)板打開LED免胃;而接受到字符“L”時(shí)音五,開發(fā)板關(guān)閉LED燈。
數(shù)據(jù)從Arduino IDE串口監(jiān)視器或者其他類似Processing羔沙,F(xiàn)lash躺涝,PD,Max/MSP之類的程序發(fā)送撬碟。
很多Arduino和Genuino開發(fā)板有一個(gè)連接到pin13的內(nèi)置LED燈诞挨。如果你的開發(fā)板沒有內(nèi)置LED燈莉撇,連接一個(gè)額外的LED燈到pin13。長(zhǎng)腿或者陽(yáng)極惶傻,通過(guò)一個(gè)220 ohm電阻連接到pin13棍郎。短腿或者陰極,連接到地银室。
示例代碼:
const int ledPin = 13; // the pin that the LED is attached to
int incomingByte; // a variable to read incoming serial data into
void setup() {
// initialize serial communication:
Serial.begin(9600);
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
}
void loop() {
// see if there's incoming serial data:
if (Serial.available() > 0) {
// read the oldest byte in the serial buffer:
incomingByte = Serial.read();
// if it's a capital H (ASCII 72), turn on the LED:
if (incomingByte == 'H') {
digitalWrite(ledPin, HIGH);
}
// if it's an L (ASCII 76) turn off the LED:
if (incomingByte == 'L') {
digitalWrite(ledPin, LOW);
}
}
}
讀取ASCII字符串
這個(gè)程序用Serial.parseInt()函數(shù)來(lái)定位非字母數(shù)字的字符的值涂佃。通常人們用逗號(hào)來(lái)區(qū)分信息的不同模塊(這種格式通常叫comma-separated-values 或者 CSV),但其他字符像空格或者句號(hào)也可以用蜈敢。這些值被粘貼成整數(shù)辜荠,用來(lái)區(qū)分RGB LED燈的顏色。你用Arduino IDE串口監(jiān)視器來(lái)發(fā)送像“5抓狭,220伯病,70”的字符串到你的開發(fā)板來(lái)改變燈光的顏色。
你需要4根線來(lái)連接上面的電路否过。一根把從開發(fā)板的電源處的5V連接到RGB LED燈的長(zhǎng)引腳午笛。
把RGB LED燈放在你的面包板上。檢查你的LED燈的數(shù)據(jù)手冊(cè)來(lái)判斷引腳苗桂,它們應(yīng)該是R,V+,G和B药磺。從5V引來(lái)的線應(yīng)該連接第二個(gè)引腳上,如電路圖所示煤伟。
用剩下的線癌佩,連接LED燈的紅陰極到pin3,綠陰極連接到pin5便锨,藍(lán)陰極連接到pin6围辙,中間串聯(lián)一個(gè)220ohm電阻。
共極的RGN LED燈分享一個(gè)共同的電源引腳放案。和使一個(gè)引腳切換高電平來(lái)點(diǎn)亮的LED燈不同酌畜,你需要使這個(gè)引腳切換成低電平,來(lái)產(chǎn)生一個(gè)電壓差卿叽。所以桥胞,發(fā)送255到analogWrite()可以使LED關(guān)閉,而發(fā)送0會(huì)使它變得最亮考婴。在下面的代碼里贩虾,你用到一些數(shù)學(xué)公式,以便你能發(fā)送一些和亮度相應(yīng)的數(shù)值沥阱。重要的是缎罢,和使用analogWrite(pin, brightness)不同,你要調(diào)用analogWrite(pin, 255-brightness).
示例代碼:
// pins for the LEDs:
const int redPin = 3;
const int greenPin = 5;
const int bluePin = 6;
void setup() {
// initialize serial:
Serial.begin(9600);
// make the pins outputs:
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
}
void loop() {
// if there's any serial available, read it:
while (Serial.available() > 0) {
// look for the next valid integer in the incoming serial stream:
int red = Serial.parseInt();
// do it again:
int green = Serial.parseInt();
// do it again:
int blue = Serial.parseInt();
// look for the newline. That's the end of your sentence:
//if (Serial.read() == '\n') {
// constrain the values to 0 - 255 and invert
// if you're using a common-cathode LED, just use "constrain(color, 0, 255);"
red = 255 - constrain(red, 0, 255);
green = 255 - constrain(green, 0, 255);
blue = 255 - constrain(blue, 0, 255);
// fade the red, green, and blue legs of the LED:
analogWrite(redPin, red);
analogWrite(greenPin, green);
analogWrite(bluePin, blue);
// print the three numbers in one string as hexadecimal:
Serial.print(red, HEX);
Serial.print(green, HEX);
Serial.println(blue, HEX);
// }
}
}
注意:
用constrain(),你可以使這些值保持在PWM控制的范圍內(nèi)策精。用這種方式舰始,如果這些值超過(guò)PWM的范圍,它將會(huì)限制在一個(gè)可行的數(shù)值咽袜。從255里減去這個(gè)數(shù)值丸卷,你就可以得出用來(lái)控制LED燈的值。綜上所述询刹,當(dāng)二極管和開發(fā)板的引腳之間有電壓差時(shí)谜嫉,這些LED燈會(huì)變亮
串口呼叫響應(yīng)
這個(gè)例子示范了用呼叫響應(yīng)(握手)方式從Arduino 或Genuino開發(fā)板到電腦的多字節(jié)通訊。
這個(gè)程序在啟動(dòng)時(shí)發(fā)送一個(gè)ASCII A(字節(jié)值65)凹联,并且等它收到來(lái)自電腦的串口回應(yīng)時(shí)重發(fā)沐兰。然后,它發(fā)送三個(gè)傳感值作為單獨(dú)字節(jié)蔽挠,并且等待電腦的另一個(gè)回應(yīng)住闯。
你可以用Arduino IDE串口監(jiān)視器來(lái)觀察發(fā)送的數(shù)據(jù),或者用Processing, Flash, PD, Max/MSP (看下面例子)等等來(lái)讀取澳淑。
把模擬傳感器(作為分壓器)通過(guò)10k ohm電阻連接到模擬引腳PIN0和PIN1寞秃。
把一個(gè)按鍵或者開關(guān)連接到數(shù)字I/O口pin2,并通過(guò)一個(gè)10k ohm電阻下拉到地偶惠。
int firstSensor = 0; // first analog sensor
int secondSensor = 0; // second analog sensor
int thirdSensor = 0; // digital sensor
int inByte = 0; // incoming serial byte
void setup() {
// start serial port at 9600 bps:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
pinMode(2, INPUT); // digital sensor is on digital pin 2
establishContact(); // send a byte to establish contact until receiver responds
}
void loop() {
// if we get a valid byte, read analog ins:
if (Serial.available() > 0) {
// get incoming byte:
inByte = Serial.read();
// read first analog input, divide by 4 to make the range 0-255:
firstSensor = analogRead(A0) / 4;
// delay 10ms to let the ADC recover:
delay(10);
// read second analog input, divide by 4 to make the range 0-255:
secondSensor = analogRead(1) / 4;
// read switch, map it to 0 or 255L
thirdSensor = map(digitalRead(2), 0, 1, 0, 255);
// send sensor values:
Serial.write(firstSensor);
Serial.write(secondSensor);
Serial.write(thirdSensor);
}
}
void establishContact() {
while (Serial.available() <= 0) {
Serial.print('A'); // send a capital A
delay(300);
}
}
串口呼叫響應(yīng)ASCII
這個(gè)例子示范了用呼叫響應(yīng)(握手)方式從Arduino 或Genuino開發(fā)板到電腦的串口通訊。
這個(gè)程序在啟動(dòng)時(shí)發(fā)送一個(gè)ASCII 字符串朗涩,并且等它收到來(lái)自電腦的串口回應(yīng)時(shí)重發(fā)忽孽。然后,它發(fā)送三個(gè)傳感值作為 ASCII解碼的數(shù)字(逗號(hào)分開谢床,換行+回車結(jié)束)兄一,并且等待電腦的另一個(gè)回應(yīng)。
你可以用Arduino IDE串口監(jiān)視器來(lái)觀察發(fā)送的數(shù)據(jù)识腿,或者用Processing, Flash, PD, Max/MSP (看下面例子)等等來(lái)讀取出革。下面的例子用逗號(hào)分開輸入的字符串,并轉(zhuǎn)換成字符串重新輸入到數(shù)字里渡讼。
比較這個(gè)和串口呼叫響應(yīng)例子骂束。他們?cè)诠餐褂玫奈帐址绞缴虾芟嗨疲@個(gè)把讀到的傳感值作為字符串解碼成箫,而另一個(gè)作為二進(jìn)制值發(fā)送展箱。而發(fā)送像ASCII-encoded的字符串承載更多的字節(jié),這意味著你可以很容易發(fā)送比255更大的字節(jié)的傳感器讀取值蹬昌。它同樣容易在串口終端程序里讀取混驰。
把模擬傳感器(作為分壓器)通過(guò)10k ohm電阻連接到模擬引腳PIN0和PIN1。
把一個(gè)按鍵或者開關(guān)連接到數(shù)字I/O口pin2,并通過(guò)一個(gè)10k ohm電阻下拉到地栖榨。
int firstSensor = 0; // first analog sensor
int secondSensor = 0; // second analog sensor
int thirdSensor = 0; // digital sensor
int inByte = 0; // incoming serial byte
void setup() {
// start serial port at 9600 bps and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
pinMode(2, INPUT); // digital sensor is on digital pin 2
establishContact(); // send a byte to establish contact until receiver responds
}
void loop() {
// if we get a valid byte, read analog ins:
if (Serial.available() > 0) {
// get incoming byte:
inByte = Serial.read();
// read first analog input:
firstSensor = analogRead(A0);
// read second analog input:
secondSensor = analogRead(A1);
// read switch, map it to 0 or 255
thirdSensor = map(digitalRead(2), 0, 1, 0, 255);
// send sensor values:
Serial.print(firstSensor);
Serial.print(",");
Serial.print(secondSensor);
Serial.print(",");
Serial.println(thirdSensor);
}
}
void establishContact() {
while (Serial.available() <= 0) {
Serial.println("0,0,0"); // send an initial string
delay(300);
}
}
Serial Event
這個(gè)例子示范了怎么用SerialEvent()函數(shù)昆汹。這個(gè)函數(shù)是從loop()里調(diào)用。如果緩沖器有串口數(shù)據(jù)婴栽,每個(gè)被找到的字符都加入到一個(gè)字符串里满粗,直到發(fā)現(xiàn)新行。在這種情況下居夹,由收到的字符組成的字符串打印并且重置變回null败潦。
什么都不要,只需要開發(fā)板連接到電腦准脂。用Arduino IDE串口監(jiān)視器發(fā)送單個(gè)或者多個(gè)字符并且返回字符串劫扒。
示例代碼:
String inputString = ""; // a String to hold incoming data
boolean stringComplete = false; // whether the string is complete
void setup() {
// initialize serial:
Serial.begin(9600);
// reserve 200 bytes for the inputString:
inputString.reserve(200);
}
void loop() {
// print the string when a newline arrives:
if (stringComplete) {
Serial.println(inputString);
// clear the string:
inputString = "";
stringComplete = false;
}
}
/*
SerialEvent occurs whenever a new data comes in the hardware serial RX. This
routine is run between each time loop() runs, so using delay inside loop can
delay response. Multiple bytes of data may be available.
*/
void serialEvent() {
while (Serial.available()) {
// get the new byte:
char inChar = (char)Serial.read();
// add it to the inputString:
inputString += inChar;
// if the incoming character is a newline, set a flag so the main loop can
// do something about it:
if (inChar == '\n') {
stringComplete = true;
}
}
}
可視顏色混合器
這個(gè)例子示范了怎么從Arduino開發(fā)板發(fā)送多個(gè)數(shù)值到電腦。從三個(gè)電位計(jì)讀到的數(shù)值被用來(lái)設(shè)置Processing或Max/MSP的后臺(tái)顏色的紅狸膏,綠和藍(lán)零件沟饥。
連接模擬傳感器到模擬引腳pin0,1湾戳,2贤旷。
這個(gè)電路用三個(gè)分壓器來(lái)產(chǎn)生來(lái)自壓力傳感電阻的模擬電壓。一個(gè)分壓器有兩個(gè)電阻串聯(lián)砾脑,以便合理地分壓幼驶。
示例代碼:
這個(gè)傳感值作為ASCII-encoded 數(shù)字從Arduino發(fā)送到電腦。這意味著每個(gè)數(shù)字是用ASCII字符“0”到“9”發(fā)送的韧衣。以“234”為例子盅藻,共發(fā)送了三個(gè)字節(jié):ASCII "2" (binary value 50), ASCII "3" (binary value 51), 和ASCII "4" (binary value 52).
const int redPin = A0; // sensor to control red color
const int greenPin = A1; // sensor to control green color
const int bluePin = A2; // sensor to control blue color
void setup() {
Serial.begin(9600);
}
void loop() {
Serial.print(analogRead(redPin));
Serial.print(",");
Serial.print(analogRead(greenPin));
Serial.print(",");
Serial.println(analogRead(bluePin));
}