Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Include libraries
- #include <OneWire.h>
- #include <DallasTemperature.h>
- #include <LiquidCrystal_I2C.h>
- // Data wire is plugged into pin 2 on the Arduino
- #define ONE_WIRE_BUS 2
- // Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
- OneWire oneWire(ONE_WIRE_BUS);
- // Pass our oneWire reference to Dallas Temperature.
- DallasTemperature sensors(&oneWire);
- char array1[]=" SunFounder "; //the string to print on the LCD
- char array2[]="hello, world! "; //the string to print on the LCD
- int tim = 500; //the value of delay time
- // initialize the library with the numbers of the interface pins
- LiquidCrystal_I2C lcd(0x27,16,2); // set the LCD address to 0x27 for a 16 chars and 2 line display
- const int buzzer = 9; //buzzer to arduino pin 9
- void setup(void)
- {
- lcd.init(); //initialize the lcd
- lcd.backlight(); //open the backlight
- pinMode (13, OUTPUT); // For laser
- pinMode(buzzer, OUTPUT); // Set buzzer - pin 9 as an output
- pinMode (13, OUTPUT); // For 7 color flash
- Serial.begin(9600); //Begin serial communication
- Serial.println("Arduino Digital Temperature // Serial Monitor Version"); //Print a message
- sensors.begin();
- }
- void loop(void)
- {
- /************************* Temperature Section *****************************/
- // Send the command to get temperatures
- sensors.requestTemperatures();
- Serial.print("Temperature is: ");
- 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
- //Update value every 1 sec.
- delay(1000);
- /************ I2C and LCD chunk ***************************************/
- // This is inspired from the the Lesson 1 Display by I2C LCD 1602 on SunFounder.com
- lcd.setCursor(15,0); // set the cursor to column 15, line 0
- for (int positionCounter1 = 0; positionCounter1 < 26; positionCounter1++)
- {
- lcd.scrollDisplayLeft(); //Scrolls the contents of the display one space to the left.
- lcd.print(array1[positionCounter1]); // Print a message to the LCD.
- delay(tim); //wait for 250 microseconds
- }
- lcd.clear(); //Clears the LCD screen and positions the cursor in the upper-left corner.
- lcd.setCursor(15,1); // set the cursor to column 15, line 1
- for (int positionCounter = 0; positionCounter < 26; positionCounter++)
- {
- lcd.scrollDisplayLeft(); //Scrolls the contents of the display one space to the left.
- lcd.print(array2[positionCounter]); // Print a message to the LCD.
- delay(tim); //wait for 250 microseconds
- }
- lcd.clear(); //Clears the LCD screen and positions the cursor in the upper-left corner.
- /************ Laser ***************************************/
- digitalWrite (13, HIGH); // open the laser head
- delay (1000); // delay one second
- digitalWrite (13, LOW); // turn off the laser head
- delay (1000); // delay one second
- /************ Buzzer ***************************************/
- tone(buzzer, 1000); // Send 1KHz sound signal...
- delay(1000); // ...for 1 sec
- noTone(buzzer); // Stop sound...
- delay(1000); // ...for 1sec
- /************ 7 Color Flash ******************************/
- digitalWrite (13, HIGH); // set the LED on
- delay (2000); // wait for a second
- digitalWrite (13, LOW); // set the LED off
- delay (2000); // wait for a second
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement