Поделки на Ардуино
Пришел из Китая набор Arduino Starter. Собрал с детьми простенькие часики.
Скетч под спойлером
/* YourDuino.com Example Software Sketch
DHT11 Humidity and Temperature Sensor test
Displayed on I2C LCD Display
Credits: Rob Tillaart
http://arduino-info.wikispaces.com/PROJECT-Temp-Humidity-Display
terry@yourduino.com
Combined with:
Mark Johnson’s code
http://uControlIt.tv
December 2012
License: GNU General Public License
Modiffied by Timofte Andrei ( http://timofteandreidiy.wordpress.com )
January 2014
*/
/*——( Import needed libraries )——*/
#include <dht11.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <Time.h>
#include <DS1307RTC.h>
const char *mt[] = {«»,»Jan»,»Feb»,»Mar»,»Apr»,»May»,»Jun»,»Jul»,»Aug»,»Sep»,»Oct»,»Nov»,»Dec»}; //months of the week also in romanian
byte termometru[8] = //icon for termometer
{
B00100,
B01010,
B01010,
B01110,
B01110,
B11111,
B11111,
B01110
};
byte picatura[8] = //icon for water droplet
{
B00100,
B00100,
B01010,
B01010,
B10001,
B10001,
B10001,
B01110,
};
/*——( Declare objects )——*/
LiquidCrystal_I2C lcd(0x3f,16,2); // Set the LCD I2C address
dht11 DHT11;
/*——( Declare Constants, Pin Numbers )——*/
#define DHT11PIN 4 //dht11 signal pin connected to D4
void setup() /*—-( SETUP: RUNS ONCE )—-*/
{
Wire.begin();
lcd.begin(16,2); // initialize the lcd for 16 chars 2 lines, turn on backlight
lcd.backlight();
lcd.clear();
lcd.createChar(1,termometru);
lcd.createChar(2,picatura);
setSyncProvider(RTC.get);
}/*—(end setup )—*/
void loop() /*—-( LOOP: RUNS CONSTANTLY )—-*/
{
afisare_temperatura(); //displaying temperature
data_si_ora(); //displaying date and time
delay(1000);
}
void afisare_temperatura()
{
int chk = DHT11.read(DHT11PIN);
lcd.setCursor(1, 1);
lcd.write(1);
lcd.setCursor(3, 1);
lcd.print((float)DHT11.temperature, 0);
lcd.setCursor(5, 1);
lcd.print((char)223); //degree sign
lcd.print(«C»);
lcd.setCursor(9, 1);
lcd.write(2);
lcd.setCursor(11, 1);
lcd.print((float)DHT11.humidity, 0);
lcd.print(«%»);
}
void data_si_ora()
{
tmElements_t tm;
(RTC.read(tm));
lcd.setCursor(0, 0);
afisare2cifre(tm.Hour);
lcd.print(«:»);
afisare2cifre(tm.Minute);
lcd.setCursor(6,0);
afisare2cifre(tm.Day);
lcd.print(«-«);
lcd.print(mt[tm.Month]);
lcd.print(«-«);
lcd.print(tmYearToCalendar(tm.Year)-2000);
}
void afisare2cifre(int numar) { //this adds a 0 before single digit numbers
if (numar >= 0 && numar < 10) {
lcd.write(‘0’);
}
lcd.print(numar);
}
/* ( THE END ) */