资源描述:
《adafruit-arduino-lesson-5-the-serial-monitor.pdf》由会员上传分享,免费在线阅读,更多相关内容在学术论文-天天文库。
1、ArduinoLesson5.TheSerialMonitorCreatedbySimonMonkGuideContentsGuideContents2Overview3TheSerialMonitor4ArduinoCode7OtherThingstoDo10©AdafruitIndustrieshttp://learn.adafruit.com/adafruit-arduino-lesson-5-the-serial-monitorPage2of11OverviewInthislesson,youwillbuildonlesson4,addingthefacilityto
2、controltheLEDsfromyourcomputerusingtheArduinoSerialMonitor.Theserialmonitoristhe'tether'betweenthecomputerandyourArduino-itletsyousendandreceivetextmessages,handyfordebuggingandalsocontrollingtheArduinofromakeyboard!Forexample,youwillbeabletosendcommandsfromyourcomputertoturnonLEDs.Inthisle
3、sson,youwilluseexactlythesamepartsandasimilarbreadboardlayoutasLesson4.So,ifyouhavenotalreadydoneso,followlesson4now.©AdafruitIndustrieshttp://learn.adafruit.com/adafruit-arduino-lesson-5-the-serial-monitorPage3of11TheSerialMonitorUploadthefollowingsketchtoyourArduino.Lateron,wewillseeexact
4、lyhowitworks./*AdafruitArduino-Lesson5.SerialMonitor*/intlatchPin=5;intclockPin=6;intdataPin=4;byteleds=0;voidsetup(){pinMode(latchPin,OUTPUT);pinMode(dataPin,OUTPUT);pinMode(clockPin,OUTPUT);updateShiftRegister();Serial.begin(9600);while(!Serial);//WaituntilSerialisready-LeonardoSerial.pri
5、ntln("EnterLEDNumber0to7or'x'toclear");}voidloop(){if(Serial.available()){charch=Serial.read();if(ch>='0'&&ch<='7'){intled=ch-'0';bitSet(leds,led);updateShiftRegister();Serial.print("TurnedonLED");Serial.println(led);}if(ch=='x'){leds=0;updateShiftRegister();Serial.println("Cleared");}}}voi
6、dupdateShiftRegister(){digitalWrite(latchPin,LOW);shiftOut(dataPin,clockPin,LSBFIRST,leds);digitalWrite(latchPin,HIGH);}©AdafruitIndustrieshttp://learn.adafruit.com/adafruit-arduino-lesson-5-the-serial-monitorPage4of11AfteryouhaveuploadedthissketchontoyourArduino,clickontheright-mostbuttono
7、nthetoolbarintheArduinoIDE.Thebuttoniscircledbelow.Thefollowingwindowwillopen.ThiswindowiscalledtheSerialMonitoranditispartoftheArduinoIDEsoftware.ItsjobistoallowyoutobothsendmessagesfromyourcomputertoanArduinoboard(overUSB)andalsotoreceivemessagesfromth