Skip to content

Instantly share code, notes, and snippets.

@yamika
Created April 29, 2016 02:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yamika/becf57793c9b9cc2a096e600f53c2d71 to your computer and use it in GitHub Desktop.
Save yamika/becf57793c9b9cc2a096e600f53c2d71 to your computer and use it in GitHub Desktop.
#include "DHT.h"
#include <Wire.h>
#include <ST7032.h>
#include <Adafruit_NeoPixel.h>
#define buttonPin 2 // LEDピン
#define buzzerPin 7
int buttonState = 0;
int duration = 500;
int ledPin = A0;
int numPixels = 12;
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(numPixels, ledPin, NEO_GRB + NEO_KHZ800);
DHT dht(A1, DHT11);
ST7032 lcd;
bool isNotifyEnabled = true;
void setup() {
pinMode(buttonPin,INPUT);
Serial.begin(9600);
dht.begin();
lcd.begin(8, 2);
lcd.setContrast(20);
lcd.print("Hello!");
delay(3000);
lcd.clear();
pixels.begin();
pixels.show();
}
int j=1;
void OK_stage(){
int i;
buttonState = digitalRead(buttonPin);
if(buttonState) {
isNotifyEnabled = !isNotifyEnabled;
j=1;
for(i=0; i<pixels.numPixels(); i++) {
pixels.setPixelColor(i, pixels.Color(0, 0, 0));
pixels.show();
}
delay(2000);
}
if(isNotifyEnabled){
for(i=0; i<j; i++) {
pixels.setPixelColor(i, pixels.Color(128, 0, 0));
}
if(j!=13){
tone(buzzerPin,880,duration);
delay(90);
pixels.show();
delay(2000);
j++;
}else {
for(i=0; i<pixels.numPixels(); i++) {
pixels.setPixelColor(i, pixels.Color(128, 128,128));
}
pixels.show();
tone(buzzerPin,262,duration);
delay(50);
for(i=0; i<pixels.numPixels(); i++) {
pixels.setPixelColor(i, pixels.Color(128, 0, 0));
}
pixels.show();
tone(buzzerPin,659,duration);
delay(100);
}
}
}
void NO_stage(){
int i;
for(i=0; i<pixels.numPixels(); i++) {
pixels.setPixelColor(i, pixels.Color(0, 0, 128));
}
pixels.show();
tone(buzzerPin,659,duration);
delay(200);
for(i=0; i<pixels.numPixels(); i++) {
pixels.setPixelColor(i, pixels.Color(0, 0, 0));
}
pixels.show();
tone(buzzerPin,330,duration);
delay(100);
}
void setAllPixelColors(int r, int g, int b) {
for(int i = 0; i < pixels.numPixels(); ++i) {
pixels.setPixelColor(i, pixels.Color(r, g, b));
}
}
void emitAllPixels(int r, int g, int b, int t) {
setAllPixelColors(r, g, b);
pixels.show();
delay(t);
setAllPixelColors(0, 0, 0);
pixels.show();
}
void SOS(){
int r, g, b;
r = g = b = 128;
int emitTs[] = {300, 300, 300, 1000, 1000, 1000, 300, 300, 300};
int delayTs [] = {1, 1, 1, 1, 1, 1, 1, 1, 1};
for(int i = 0; i < 6; ++i) {
emitAllPixels(r, g, b, emitTs[i]);
delay(100);
}
}
void lcd_print(float h,float t){
lcd.print("H:");
lcd.print(h);
lcd.setCursor(0,1);
lcd.print("T:");
lcd.print(t);
lcd.println(" *C");
}
void worning_print(){
lcd.print("Go Home!!");
}
void Potate(){
lcd.print("Potate!");
}
int tmin=0;
void loop() {
buttonState = digitalRead(buttonPin);
if(buttonState) {
isNotifyEnabled = !isNotifyEnabled;
delay(2000);
}
int i,tag=0;
delay(1000);
float h = dht.readHumidity();
float t = dht.readTemperature();
lcd.home();
if(t > tmin){
tag=0;
}else{
tag=1;
}
if(isNotifyEnabled) {
if(tag==0){
OK_stage();
if((millis()/1000) % 2 == 0 ){
if(j>=13){
lcd.clear();
worning_print();
}else{
lcd_print(h,t);
}
}else if((millis()/1000) % 2 ==1 ){
if(j>=13){
lcd.clear();
worning_print();
}else{
lcd.clear();
Potate();
}
}else if(j > 13){
lcd.clear();
worning_print();
}
}else if(tag==1){
// NO_stage();
worning_print();
if((millis()/1000) >= 150){
SOS();
}else{
NO_stage();
}
}
}else{
tmin+=40;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment