Last active
June 12, 2019 07:06
-
-
Save fxprime/496ddb28b515b56424e88352bb147322 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| ArduinoNa.com | |
| อ่านค่า analog จาก pin A0-A2 และปริ้นค่าออกทาง Serial port | |
| */ | |
| int sensor_L , sensor_C , sensor_R ; //ตัวแปรไว้เก็บค่า sensor | |
| String tmp ; | |
| int ADC_stabilize = 5 ; | |
| void setup ( ) { | |
| // initialize เริ่มให้บอร์ดสื่อสารกับคอมด้วยความเร็ว 9600 | |
| Serial . begin ( 9600 ) ; | |
| } | |
| void loop ( ) { | |
| //อ่านค่าลงตัวแปรต่างๆ | |
| sensor_L = digitalRead ( A0 ) ; //ใช้เป็น AnalogRead ก็ได้ ค่าจะออกมาตามระดับความเข้ม 0-1023 | |
| delay ( ADC_stabilize ) ; //stabilize | |
| sensor_C = digitalRead ( A1 ) ; | |
| delay ( ADC_stabilize ) ; | |
| sensor_R = digitalRead ( A2 ) ; | |
| delay ( ADC_stabilize ) ; | |
| tmp = "L=" + String ( sensor_L ) + " C=" + String ( sensor_C ) + " R=" + String ( sensor_R ) ; | |
| // แสดงค่า Output ออกทาง Serial port | |
| Serial . println ( tmp ) ; | |
| // รอก่อนอ่านรอบถัดไป | |
| delay ( 1000 ) ; //1000=1 sec | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment