検索条件
タグで絞り込み
電子工作(2)
全3件
(1/1ページ)
#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);
}
}

pi@coriander ~ $ ntpdc -p
remote local st poll reach delay offset disp
=======================================================================
*sv2.localdomain 192.168.1.126 2 1024 377 0.00793 0.001239 0.12054
=einzbern.turena 192.168.1.126 2 1024 377 0.00792 0.001479 0.12267
=ntp.kiba.net 192.168.1.126 2 512 376 0.01930 0.001555 0.15672
=v157-7-235-92.z 192.168.1.126 2 1024 377 0.00993 0.000767 0.08698
GPIOを操作する雑なスクリプトをやっつけて...、#! /bin/sh echo $1 > /sys/class/gpio/export echo out > /sys/class/gpio/gpio$1/directiongpio-toggle.sh
#! /bin/sh echo $2 > /sys/class/gpio/gpio$1/valueroot の crontab に登録。6:00 - 19:00 の間、LEDを照射する。
0 6 * * * sh /home/pi/scripts/toggle-gpio.sh 4 1 0 6 * * * sh /home/pi/scripts/toggle-gpio.sh 17 1 0 19 * * * sh /home/pi/scripts/toggle-gpio.sh 4 0 0 19 * * * sh /home/pi/scripts/toggle-gpio.sh 17 0Raspberry Pi に WiFi を繋いだので時刻ずれの心配がなくなったんだけど、気軽に電源を落とせなくなってしまった。