Advertisement
Guest User

Untitled

a guest
Mar 24th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.38 KB | None | 0 0
  1. //Include libraries
  2. #include <OneWire.h>
  3. #include <DallasTemperature.h>
  4. #include <LiquidCrystal_I2C.h>
  5.  
  6. // Data wire is plugged into pin 2 on the Arduino
  7. #define ONE_WIRE_BUS 2
  8. // Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
  9. OneWire oneWire(ONE_WIRE_BUS);
  10. // Pass our oneWire reference to Dallas Temperature.
  11. DallasTemperature sensors(&oneWire);
  12.  
  13. char array1[]=" SunFounder "; //the string to print on the LCD
  14. char array2[]="hello, world! "; //the string to print on the LCD
  15. int tim = 500; //the value of delay time
  16. // initialize the library with the numbers of the interface pins
  17. LiquidCrystal_I2C lcd(0x27,16,2); // set the LCD address to 0x27 for a 16 chars and 2 line display
  18.  
  19. const int buzzer = 9; //buzzer to arduino pin 9
  20.  
  21. void setup(void)
  22. {
  23. lcd.init(); //initialize the lcd
  24. lcd.backlight(); //open the backlight
  25.  
  26. pinMode (13, OUTPUT); // For laser
  27.  
  28. pinMode(buzzer, OUTPUT); // Set buzzer - pin 9 as an output
  29.  
  30. pinMode (13, OUTPUT); // For 7 color flash
  31.  
  32. Serial.begin(9600); //Begin serial communication
  33. Serial.println("Arduino Digital Temperature // Serial Monitor Version"); //Print a message
  34. sensors.begin();
  35.  
  36. }
  37.  
  38. void loop(void)
  39. {
  40. /************************* Temperature Section *****************************/
  41. // Send the command to get temperatures
  42. sensors.requestTemperatures();
  43. Serial.print("Temperature is: ");
  44. Serial.println(sensors.getTempCByIndex(0)); //Why "byIndex"? You can have more than one IC on the same bus. 0 refers to the first IC on the wire
  45. //Update value every 1 sec.
  46. delay(1000);
  47.  
  48. /************ I2C and LCD chunk ***************************************/
  49. // This is inspired from the the Lesson 1 Display by I2C LCD 1602 on SunFounder.com
  50.  
  51. lcd.setCursor(15,0); // set the cursor to column 15, line 0
  52. for (int positionCounter1 = 0; positionCounter1 < 26; positionCounter1++)
  53. {
  54. lcd.scrollDisplayLeft(); //Scrolls the contents of the display one space to the left.
  55. lcd.print(array1[positionCounter1]); // Print a message to the LCD.
  56. delay(tim); //wait for 250 microseconds
  57. }
  58. lcd.clear(); //Clears the LCD screen and positions the cursor in the upper-left corner.
  59. lcd.setCursor(15,1); // set the cursor to column 15, line 1
  60. for (int positionCounter = 0; positionCounter < 26; positionCounter++)
  61. {
  62. lcd.scrollDisplayLeft(); //Scrolls the contents of the display one space to the left.
  63. lcd.print(array2[positionCounter]); // Print a message to the LCD.
  64. delay(tim); //wait for 250 microseconds
  65. }
  66. lcd.clear(); //Clears the LCD screen and positions the cursor in the upper-left corner.
  67.  
  68. /************ Laser ***************************************/
  69. digitalWrite (13, HIGH); // open the laser head
  70. delay (1000); // delay one second
  71. digitalWrite (13, LOW); // turn off the laser head
  72. delay (1000); // delay one second
  73.  
  74. /************ Buzzer ***************************************/
  75. tone(buzzer, 1000); // Send 1KHz sound signal...
  76. delay(1000); // ...for 1 sec
  77. noTone(buzzer); // Stop sound...
  78. delay(1000); // ...for 1sec
  79.  
  80. /************ 7 Color Flash ******************************/
  81. digitalWrite (13, HIGH); // set the LED on
  82. delay (2000); // wait for a second
  83. digitalWrite (13, LOW); // set the LED off
  84. delay (2000); // wait for a second
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement