diff --git a/sketch_aug10d.ino b/sketch_aug10d.ino new file mode 100644 index 0000000..aaead48 --- /dev/null +++ b/sketch_aug10d.ino @@ -0,0 +1,32 @@ +#include + +Stepper myStepper(2048,4,5,7,8); + +int num; +int stup; + +void setup() { + // put your setup code here, to run once: + pinMode(2, INPUT); // объявляем пин 2 как вход + pinMode(3, INPUT); // объявляем пин 2 как вход + myStepper.setSpeed(10); +} + +void loop() { + // put your main code here, to run repeatedly: + if (digitalRead(2) == HIGH) // когда на пин 2 поступает высокий сигнал + { + stup=0; + myStepper.step(0); + } + if (digitalRead(3) == HIGH) + { + stup=1; + } + delay(1000); + if (stup == 1) + { + num=num+2048; + myStepper.step(num); + } +} diff --git a/sketch_aug10e.ino b/sketch_aug10e.ino new file mode 100644 index 0000000..312c719 --- /dev/null +++ b/sketch_aug10e.ino @@ -0,0 +1,25 @@ +#include "DHT.h" + +#define DHTPIN 2 // Тот самый номер пина, о котором упоминалось выше +// Одна из следующих строк закомментирована. Снимите комментарий, если подключаете датчик DHT11 к arduino +DHT dht(DHTPIN, DHT22); //Инициация датчика +//DHT dht(DHTPIN, DHT11); +void setup() { + Serial.begin(9600); + dht.begin(); +} +void loop() { + delay(2000); // 2 секунды задержки + float h = dht.readHumidity(); //Измеряем влажность + float t = dht.readTemperature(); //Измеряем температуру + if (isnan(h) || isnan(t)) { // Проверка. Если не удается считать показания, выводится «Ошибка считывания», и программа завершает работу + Serial.println("Ошибка считывания"); + return; + } + Serial.print("Влажность: "); + Serial.print(h); + Serial.print(" %\t"); + Serial.print("Температура: "); + Serial.print(t); + Serial.println(" *C "); //Вывод показателей на экран +} diff --git a/sketch_aug10f.ino b/sketch_aug10f.ino new file mode 100644 index 0000000..d1fbb9e --- /dev/null +++ b/sketch_aug10f.ino @@ -0,0 +1,39 @@ +#include // Добавляем необходимые библиотеки +#include "DHT.h" +#define RED 2 // Присваиваем имя RED для пина 11 +#define GREEN 12 // Присваиваем имя GREEN для пина 12 +#define BLUE 13 // Присваиваем имя BLUE для пина 13 +#define DHTPIN A0 // к какому пину будет подключен сигнальный выход датчика +//выбор используемого датчика +#define DHTTYPE DHT11 // DHT 11 +//#define DHTTYPE DHT22 // DHT 22 (AM2302) +//#define DHTTYPE DHT21 // DHT 21 (AM2301) +//инициализация датчика +DHT dht(DHTPIN, DHTTYPE); +void setup() +{ +Serial.begin(9600); +dht.begin(); +pinMode(RED, OUTPUT); // Используем Pin11 для вывода + pinMode(GREEN, OUTPUT); // Используем Pin12 для вывода + pinMode(BLUE, OUTPUT); // Используем Pin13 для вывода + digitalWrite(RED, HIGH); // Включаем красный свет +} +void loop() { +// Добавляем паузы в несколько секунд между измерениями +delay(2000); +// Reading temperature or humidity takes about 250 milliseconds! +// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor) +float h = dht.readHumidity(); +// Read temperature as Celsius +float t = dht.readTemperature(); +// Read temperature as Fahrenheit +float f = dht.readTemperature(true); +Serial.println(h); +if (h > 70) +{ + digitalWrite(RED, HIGH); // Включаем красный свет +} else { + digitalWrite(RED, LOW); // Включаем красный свет +} +} diff --git a/sketch_aug10i.ino b/sketch_aug10i.ino new file mode 100644 index 0000000..61f0e77 --- /dev/null +++ b/sketch_aug10i.ino @@ -0,0 +1,62 @@ +#define RED 4 +#define GREEN 3 +#define BLUE 2 + +String comand; +byte wait; +int jober; +int looper; +int IDarg = 0; +String ParsedCommand[20]; + +void setup() { + Serial.begin(9600); + pinMode(RED, OUTPUT); + pinMode(GREEN, OUTPUT); + pinMode(BLUE, OUTPUT); +} + +char getCharCommand(){ + if (Serial.available() > 0) { + char cmdraw = Serial.read(); + if (cmdraw > 0) return cmdraw; + } + +} + +void proc(String* com) { + if(com == "RGBLR") { + Serial.println("Введите 1 или 2"); + wait = 1; + jober = 1; + } +} + +void job() { + if (Serial.available()>0) { + char prom = Serial.read(); + if (jober == 1) { + if (prom == 1) { + digitalWrite(RED, HIGH); + } else { + digitalWrite(RED, LOW); + } + } + } +} + +void loop() { + if (wait == 1) { job; } + while (looper<100) { + char CharCommand = getCharCommand(); + if (CharCommand != "?") { + Serial.print(CharCommand); + ParsedCommand[IDarg] += CharCommand; + Serial.println(" "); + proc(ParsedCommand); + IDarg = 0; + for (int i = 0;i<=20;i++) {ParsedCommand[i]="";} + looper++; + } + } +} diff --git a/sketch_aug18a.ino b/sketch_aug18a.ino new file mode 100644 index 0000000..aa1de39 --- /dev/null +++ b/sketch_aug18a.ino @@ -0,0 +1,124 @@ + +#include + +#include + +#include + +long note; +long duration; + +#include "IRremote.h" + +IRrecv irrecv(2); // указываем вывод, к которому подключен приемник +int tonePin = 3; + +decode_results results; + +File myFile; + +#define SizeRegisterModules 20 + +int IDarg = 0; +String ParsedCommand[SizeRegisterModules]; + +void ShowError(String errorMessage){ + Serial.println("Error: \n "+errorMessage); +} + +void ShowMessage(String type, String Message){ + Serial.println("["+type+"] "+Message); +} + +void Play(String *args){ + Serial.println(args[0]); + Serial.println(args[1]); + Serial.println(args[2]); + if(args[0] == "tone") { + String prom = args[1]; + prom.replace("\r\n", ""); + note = prom.toInt(); + Serial.println(prom); + prom = args[2]; + prom.replace("\r\n", ""); + duration = prom.toInt(); + Serial.println(note); + Serial.println(duration); + Serial.println(prom); + NewTone(6,note,duration); + note = 0; + duration = 0; + prom = ""; + } + if(args[0] == "delay") { + Serial.println("delay process"); + String prom = args[1]; + prom.replace("\n",""); + duration = prom.toInt(); + Serial.println(prom); + Serial.println(duration); + delay(duration); + duration = 0; + prom = ""; + } +} + +char getCharCommand(){ + if (myFile.available() > 0) { + char cmdraw = myFile.read(); + if (cmdraw > 0) return cmdraw; + } + return '?'; +} + +void songone(){ +myFile = SD.open("1"); +if (myFile) { +Serial.println("1:"); +// считываем все данные из файла: +while (myFile.available()) { +char CharCommand = getCharCommand(); + if (CharCommand != ';' && CharCommand != '?'){ + //Serial.print(CharCommand); + if (CharCommand == ','){ + IDarg++; + }else{ + ParsedCommand[IDarg] += CharCommand; + } + }else if(CharCommand == ';'){ + //Serial.println(" "); + Play(ParsedCommand); + IDarg = 0; + for (int i = 0;i<=20;i++) {ParsedCommand[i]="";} + //Serial.print(">"); + } +} +// закрываем файл: +myFile.close(); +} else { +// если файл не открылся, отображаем сообщение об ошибке: +Serial.println("error opening-"); +} +} + +void setup() { + Serial.begin(9600); // выставляем скорость COM порта + irrecv.enableIRIn(); // запускаем прием + pinMode(4, OUTPUT); + if (!SD.begin(4)) { + Serial.println("SD initialization failed!"); + return; + } +} + +void loop() { + if ( irrecv.decode( &results )) { // если данные пришли + switch ( results.value ) { + case 16724175: + songone(); + break; + } + + irrecv.resume(); // принимаем следующую команду + } +} diff --git a/water_detect.ino b/water_detect.ino new file mode 100644 index 0000000..2226ca6 --- /dev/null +++ b/water_detect.ino @@ -0,0 +1,31 @@ +#define PIN_ANALOG_RAIN_SENSOR A1 // Аналоговый вход для сигнала датчика протечки и дождя +#define PIN_DIGITAL_RAIN_SENSOR 5 // Цифровой вход для сигнала датчика протечки и дождя + +void setup(){ + Serial.begin(9600); + pinMode(2, OUTPUT); // Используем Pin12 для вывода + pinMode(7, OUTPUT); // Используем Pin13 для вывода +} +void loop(){ + int sensorValue = analogRead(PIN_ANALOG_RAIN_SENSOR); // Считываем данные с аналогового порта + Serial.print("Analog value: "); + Serial.println(sensorValue); // Выводим аналоговое значение в монитр порта + if(sensorValue > 1000) + { + digitalWrite(2, HIGH); // Включаем красный свет + Serial.print("Analog value: "); + } else { + digitalWrite(2, LOW); // Включаем красный свет + } + + sensorValue = digitalRead(PIN_DIGITAL_RAIN_SENSOR); // Считываем данные с цифрового порта + Serial.print("Digital value: "); + Serial.println(sensorValue); // Выводим цифровое значение в монитр порта + if(sensorValue == 1) + { + digitalWrite(7, HIGH); // Включаем красный свет + } else { + digitalWrite(7, LOW); // Включаем красный свет + } + delay(1000); // Задержка между измерениями +}