検索条件
全6件
(1/2ページ)
int SENSOR = 8; int OUTPIN = 6; void setup() { // put your setup code here, to run once: pinMode(SENSOR, INPUT); pinMode(OUTPIN, OUTPUT); Serial.begin(9600); } void loop() { // put your main code here, to run repeatedly: delay(1000); static int cur = 0, prev = -1, t = 0; char stat[4]; cur = digitalRead(SENSOR); if (prev == cur) { t++; } else { digitalWrite(OUTPIN, cur); Serial.print("Time: "); Serial.println(t); Serial.print("Now: "); Serial.println(cur ? "on" : "off"); prev = cur; t = 0; } }
#include <Sodaq_DS3231.h> #include <Wire.h> #include <LiquidCrystal.h> // initialize the library with the numbers of the interface pins LiquidCrystal lcd(12, 11, 5, 4, 3, 2); //DateTime dt(2015, 10, 07, 01, 17, 0, 3); void setup() { Serial.begin(9600); Wire.begin(); rtc.begin(); // rtc.setDateTime(dt); // put your setup code here, to run once: lcd.begin(16, 2); // Print a message to the LCD. lcd.print("Artificial Sun for PAXI"); pinMode(7, OUTPUT); } void loop() { char buf[16]; int deg, hm, lighton, lightoff; delay(250); // set the cursor to column 0, line 1 // (note: line 1 is the second row, since counting begins with 0): lcd.setCursor(0, 1); // print the number of seconds since reset: DateTime now = rtc.now(); rtc.convertTemperature(); deg = rtc.getTemperature(); snprintf(buf, 16, "%02d:%02d:%02d %0d deg", now.hour(), now.minute(), now.second(), deg); lcd.print(buf); Serial.println(buf); // blink //digitalWrite(7, now.second() % 2 ? HIGH : LOW ); // timer snprintf(buf, 5, "%02d%02d%02d", now.hour(), now.minute()); hm = atoi(buf); // if (hm > 700 && hm < 1800) { if (hm > 115 && hm < 119) { digitalWrite(7, HIGH); } else { digitalWrite(7, LOW); } }