วันอาทิตย์ที่ 15 กรกฎาคม พ.ศ. 2561

  1. /*
  2. Adafruit Arduino - Lesson 12. Light and Temperature
  3. */
  4.  
  5. #include <LiquidCrystal.h>
  6.  
  7. int tempPin = 0;
  8. int lightPin = 1;
  9.  
  10. // BS E D4 D5 D6 D7
  11. LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
  12.  
  13. void setup()
  14. {
  15. lcd.begin(16, 2);
  16. }
  17.  
  18. void loop()
  19. {
  20. // Display Temperature in C
  21. int tempReading = analogRead(tempPin);
  22. float tempVolts = tempReading * 5.0 / 1024.0;
  23. float tempC = (tempVolts - 0.5) * 100.0;
  24. float tempF = tempC * 9.0 / 5.0 + 32.0;
  25. // ----------------
  26. lcd.print("Temp F ");
  27. lcd.setCursor(6, 0);
  28. lcd.print(tempF);
  29. // Display Light on second row
  30. int lightReading = analogRead(lightPin);
  31. lcd.setCursor(0, 1);
  32. // ----------------
  33. lcd.print("Light ");
  34. lcd.setCursor(6, 1);
  35. lcd.print(lightReading);
  36. delay(500);
  37. }

ไม่มีความคิดเห็น:

แสดงความคิดเห็น

Internet of Things (IoT)

Internet of Things หรือ IoT  Internet of Things (IoT)  คือ การที่อุปกรณ์อิเล็กทรอนิกส์ต่างๆ สามารถเชื่อมโยงหรือส่งข้อมูลถึงกันได้ด้วยอิ...