_08_photoresistance.ino 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /***********************************************************
  2. File name: 08_photoresistance.ino
  3. Description: We measure the light intensity of information with
  4. photosensitive resistance, and displayed on the
  5. LCD1602.
  6. Website: www.adeept.com
  7. E-mail: support@adeept.com
  8. Author: Tom
  9. Date: 2015/05/02
  10. ***********************************************************/
  11. #include <LiquidCrystal.h>
  12. char array1[]=" Adeept test "; //the string to print on the LCD
  13. char array2[]=" DATA: 0000 "; //the string to print on the LCD
  14. int tim = 50; //the value of delay time
  15. // initialize the library with the numbers of the interface pins
  16. LiquidCrystal lcd(4, 6, 10, 11, 12, 13);
  17. int photoresistorPin = 0; // potentiometer wiper (middle terminal) connected to analog pin 3
  18. void setup()
  19. {
  20. lcd.begin(16, 2); // set up the LCD's number of columns and rows:
  21. lcd.clear(); //Clears the LCD screen and positions the cursor in the upper-left corner
  22. lcd.setCursor(0,0); // set the cursor to column 15, line 0
  23. for (int positionCounter1 = 0; positionCounter1 < 16; positionCounter1++)
  24. {
  25. lcd.print(array1[positionCounter1]); // Print a message to the LCD.
  26. delay(tim); //wait for 250 microseconds
  27. }
  28. }
  29. void loop()
  30. {
  31. array2[9]=analogRead(photoresistorPin)/1000+0x30; //Take one thousand - bit data
  32. array2[10]=analogRead(photoresistorPin)/100%10+0x30;//Take one hundred - bit data
  33. array2[11]=analogRead(photoresistorPin)/10%10+0x30; //Take ten-bit data
  34. array2[12]=analogRead(photoresistorPin)%10+0x30; //Take a bit of data
  35. lcd.setCursor(0,1); // set the cursor to column 15, line 1
  36. for (int positionCounter3 = 0; positionCounter3 < 16; positionCounter3++)
  37. {
  38. lcd.print(array2[positionCounter3]); // Print a message to the LCD.
  39. delay(tim); //wait for 250 microseconds
  40. }
  41. }