-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit aae3f3e
Showing
107 changed files
with
12,513 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
shiftOut ra 1 Module LED 7 đoạn đơn | ||
*/ | ||
//chân ST_CP của 74HC595 | ||
int latchPin = 8; | ||
//chân SH_CP của 74HC595 | ||
int clockPin = 12; | ||
//Chân DS của 74HC595 | ||
int dataPin = 11; | ||
|
||
// Ta sẽ xây dựng mảng hằng số với các giá trị cho trước | ||
// Các bit được đánh số thứ tự (0-7) từ phải qua trái (tương ứng với A-F,DP) | ||
// Vì ta dùng LED 7 đoạn chung cực dương nên với các bit 0 | ||
// thì các đoạn của LED 7 đoạn sẽ sáng | ||
// với các bit 1 thì đoạn ấy sẽ tắt | ||
|
||
//mảng có 10 số (từ 0-9) và | ||
const byte Seg[10] = { | ||
0b11000000,//0 - các thanh từ a-f sáng | ||
0b11111001,//1 - chỉ có 2 thanh b,c sáng | ||
0b10100100,//2 | ||
0b10110000,//3 | ||
0b10011001,//4 | ||
0b10010010,//5 | ||
0b10000010,//6 | ||
0b11111000,//7 | ||
0b10000000,//8 | ||
0b10010000,//9 | ||
}; | ||
|
||
|
||
void setup() { | ||
//Bạn BUỘC PHẢI pinMode các chân này là OUTPUT | ||
pinMode(latchPin, OUTPUT); | ||
pinMode(clockPin, OUTPUT); | ||
pinMode(dataPin, OUTPUT); | ||
} | ||
|
||
void HienThiLED7doan(unsigned long Giatri, byte SoLed = 2) { | ||
|
||
byte *array = new byte[SoLed]; | ||
for (byte i = 0; i < SoLed; i++) { | ||
//Lấy các chữ số từ phải quá trái | ||
array[i] = (byte)(Giatri % 10UL); | ||
Giatri = (unsigned long)(Giatri /10UL); | ||
} | ||
digitalWrite(latchPin, LOW); | ||
for (int i = 0; i < 2; i++) | ||
shiftOut(dataPin, clockPin, MSBFIRST, Seg[array[i]]); | ||
|
||
digitalWrite(latchPin, HIGH); | ||
free(array); | ||
} | ||
|
||
|
||
void loop() { | ||
static unsigned long point = 0; | ||
|
||
HienThiLED7doan(point, 2); | ||
|
||
point = (point + 1) % 100UL; // Vòng tuần hoàn từ 0--99 | ||
delay(500);//Đợi 0.5 s cho mỗi lần tăng số | ||
} |
48 changes: 48 additions & 0 deletions
48
7SEG/3 7SEG/3_con_7SEG_down_count/3_con_7SEG_down_count.ino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
//chân ST_CP của 74HC595 | ||
int latchPin = 6; | ||
//chân SH_CP của 74HC595 | ||
int clockPin = 7; | ||
//Chân DS của 74HC595 | ||
int dataPin = 5; | ||
const byte Seg[10] = { | ||
0b11000000,//0 | ||
0b11111001,//1 | ||
0b10100100,//2 | ||
0b10110000,//3 | ||
0b10011001,//4 | ||
0b10010010,//5 | ||
0b10000010,//6 | ||
0b11111000,//7 | ||
0b10000000,//8 | ||
0b10010000,//9 | ||
}; | ||
|
||
void setup() { | ||
pinMode(latchPin, OUTPUT); | ||
pinMode(clockPin, OUTPUT); | ||
pinMode(dataPin, OUTPUT); | ||
} | ||
|
||
void SEG7display(unsigned long value, byte SEG7Count = 3) { | ||
|
||
byte *array = new byte[SEG7Count]; | ||
for (byte i = 0; i < SEG7Count; i++) { | ||
//Lấy các chữ số từ phải quá trái | ||
array[i] = (byte)(value % 10UL); | ||
value = (unsigned long)(value /10UL); | ||
} | ||
digitalWrite(latchPin, LOW); | ||
for (int i = 0; i < SEG7Count; i++) | ||
shiftOut(dataPin, clockPin, MSBFIRST, Seg[array[i]]); | ||
|
||
digitalWrite(latchPin, HIGH); | ||
free(array); | ||
} | ||
|
||
|
||
void loop() { | ||
static unsigned long point = 999; | ||
SEG7display(point, 3); | ||
point = (unsigned long)(point-1); | ||
delay(50); | ||
} |
84 changes: 84 additions & 0 deletions
84
7SEG/den giao thong/2_con_7SEG_random_so_giam_dan/2_con_7SEG_random_so_giam_dan.ino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
//chân ST_CP của 74HC595 | ||
int latchPin = 6; | ||
//chân SH_CP của 74HC595 | ||
int clockPin = 7; | ||
//Chân DS của 74HC595 | ||
int dataPin = 5; | ||
int RED_LED = 8, YELLOW_LED = 9, GREEN_LED =10; | ||
const byte Seg[10] = { | ||
0b11000000,//0 | ||
0b11111001,//1 | ||
0b10100100,//2 | ||
0b10110000,//3 | ||
0b10011001,//4 | ||
0b10010010,//5 | ||
0b10000010,//6 | ||
0b11111000,//7 | ||
0b10000000,//8 | ||
0b10010000,//9 | ||
}; | ||
|
||
void setup() { | ||
pinMode(latchPin, OUTPUT); | ||
pinMode(clockPin, OUTPUT); | ||
pinMode(dataPin, OUTPUT); | ||
pinMode(8,OUTPUT); | ||
pinMode(9,OUTPUT); | ||
pinMode(10,OUTPUT); | ||
randomSeed(analogRead(A0)); | ||
Serial.begin(9600); | ||
} | ||
|
||
void SEG7display(unsigned long value, byte SEG7Count = 2) { | ||
|
||
byte *array = new byte[SEG7Count]; | ||
for (byte i = 0; i < SEG7Count; i++) { | ||
//Lấy các chữ số từ phải quá trái | ||
array[i] = (byte)(value % 10UL); | ||
value = (unsigned long)(value /10UL); | ||
} | ||
digitalWrite(latchPin, LOW); | ||
for (int i = 0; i < SEG7Count; i++) | ||
shiftOut(dataPin, clockPin, MSBFIRST, Seg[array[i]]); | ||
|
||
digitalWrite(latchPin, HIGH); | ||
free(array); | ||
} | ||
|
||
|
||
void loop() { | ||
static long point; | ||
|
||
point = random(20,90); | ||
do{ | ||
digitalWrite(RED_LED,HIGH); | ||
SEG7display(point, 2); | ||
point = (long)(point-1); | ||
delay(1000); | ||
} while (point >=0); | ||
delay(100); | ||
digitalWrite(RED_LED,LOW); | ||
delay(100); | ||
|
||
point = random(20,90); | ||
do{ | ||
digitalWrite(GREEN_LED,HIGH); | ||
SEG7display(point, 2); | ||
point = (long)(point-1); | ||
delay(1000); | ||
} while (point >=0); | ||
delay(100); | ||
digitalWrite(GREEN_LED,LOW); | ||
delay(100); | ||
|
||
point = 3; | ||
do{ | ||
digitalWrite(YELLOW_LED,HIGH); | ||
SEG7display(point, 2); | ||
point = (long)(point-1); | ||
delay(1000); | ||
} while (point >=0); | ||
delay(100); | ||
digitalWrite(YELLOW_LED,LOW); | ||
delay(100); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
int dataPin = 11,latchPin = 8, clockPin = 12; | ||
const int SEG[10]{ | ||
0b11000000, //0(g->a) | ||
0b11111001, | ||
0b10100100, | ||
0b10110000, | ||
0b10011001, | ||
0b10010010, | ||
0b10000010, | ||
0b11111000, | ||
0b10000000, | ||
0b10010000 | ||
}; | ||
|
||
void setup() { | ||
// put your setup code here, to run once: | ||
pinMode(dataPin,OUTPUT); | ||
pinMode(latchPin,OUTPUT); | ||
pinMode(clockPin,OUTPUT); | ||
} | ||
|
||
void loop() { | ||
// put your main code here, to run repeatedly: | ||
for(int i = 0;i<10;i++){ | ||
digitalWrite(latchPin,LOW); | ||
shiftOut(dataPin,clockPin,MSBFIRST,SEG[i]); | ||
digitalWrite(latchPin,HIGH); | ||
delay(1000); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#include <Wire.h> | ||
#include "SparkFun_SCD4x_Arduino_Library.h" //Click here to get the library: http://librarymanager/All#SparkFun_SCD4x | ||
SCD4x mySensor; | ||
void setup() | ||
{ | ||
Serial.begin(115200); | ||
Serial.println(F("SCD4x Example")); | ||
Wire.begin(); | ||
|
||
//mySensor.enableDebugging(); // Uncomment this line to get helpful debug messages on Serial | ||
|
||
//.begin will start periodic measurements for us (see the later examples for details on how to override this) | ||
if (mySensor.begin() == false) | ||
{ | ||
Serial.println(F("Sensor not detected. Please check wiring. Freezing...")); | ||
while (1) | ||
; | ||
} | ||
|
||
//The SCD4x has data ready every five seconds | ||
} | ||
|
||
void loop() | ||
{ | ||
if (mySensor.readMeasurement()) // readMeasurement will return true when fresh data is available | ||
{ | ||
Serial.println(); | ||
|
||
Serial.print(F("CO2(ppm):")); | ||
Serial.print(mySensor.getCO2()); | ||
|
||
Serial.print(F("\tTemperature(C):")); | ||
Serial.print(mySensor.getTemperature(), 1); | ||
|
||
Serial.print(F("\tHumidity(%RH):")); | ||
Serial.print(mySensor.getHumidity(), 1); | ||
|
||
Serial.println(); | ||
} | ||
else | ||
Serial.print(F(".")); | ||
|
||
delay(500); | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
void setup(){ | ||
Serial.begin(9600); | ||
} | ||
|
||
void loop(){ | ||
int bientro = analogRead(A0); | ||
Serial.println(bientro); | ||
int voltage; | ||
voltage = map(bientro,0,1023,0,5000); | ||
Serial.println(voltage); | ||
Serial.println(); | ||
delay(200); | ||
} |
33 changes: 33 additions & 0 deletions
33
Change_RES/Change_RES_led/Change_RES_led/Change_RES_led.ino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
byte ledPin[] = {8,9,10}; | ||
void setup() { | ||
// put your setup code here, to run once: | ||
for(int i =0; i< sizeof(ledPin);i++){ | ||
pinMode(ledPin[i],OUTPUT); | ||
digitalWrite(ledPin[i],LOW); | ||
} | ||
Serial.begin(9600); | ||
} | ||
|
||
void loop() { | ||
// put your main code here, to run repeatedly: | ||
int changeRes = analogRead(A0); | ||
Serial.println(changeRes); | ||
int voltage = map(changeRes,0,1023,0,5000); | ||
Serial.println(voltage); | ||
Serial.println(); | ||
if(changeRes >0 && changeRes <=341){ | ||
digitalWrite(8,HIGH); | ||
digitalWrite(9,LOW); | ||
digitalWrite(10,LOW); | ||
} | ||
if(changeRes >341 && changeRes <=682){ | ||
digitalWrite(8,LOW); | ||
digitalWrite(9,HIGH); | ||
digitalWrite(10,LOW); | ||
} | ||
if(changeRes >682 && changeRes <=1023){ | ||
digitalWrite(8,LOW); | ||
digitalWrite(9,LOW); | ||
digitalWrite(10,HIGH); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#include <FirebaseESP32.h> | ||
#include <WiFi.h> | ||
#include "DHT.h" | ||
|
||
#define FIREBASE_HOST "esp32-smart-plant-default-rtdb.firebaseio.com/" | ||
#define WIFI_SSID "HOANG DAT" // Change the name of your WIFI | ||
#define WIFI_PASSWORD "24072002" // Change the password of your WIFI | ||
#define FIREBASE_Authorization_key "akdXuIccUekQm4AdH1c9ToAm5v25MoFahWmQh3ys" | ||
|
||
#define DHTPIN 4 | ||
|
||
#define DHTTYPE DHT11 | ||
DHT dht(DHTPIN, DHTTYPE); | ||
|
||
FirebaseData firebaseData; | ||
FirebaseJson json; | ||
|
||
void setup() { | ||
|
||
Serial.begin(115200); | ||
dht.begin(); | ||
WiFi.begin (WIFI_SSID, WIFI_PASSWORD); | ||
Serial.print("Connecting..."); | ||
while (WiFi.status() != WL_CONNECTED) | ||
{ | ||
Serial.print("."); | ||
delay(300); | ||
} | ||
Serial.println(); | ||
Serial.print("IP Address: "); | ||
Serial.println(WiFi.localIP()); | ||
Serial.println(); | ||
Firebase.begin(FIREBASE_HOST,FIREBASE_Authorization_key); | ||
|
||
} | ||
|
||
void loop() { | ||
|
||
float hum = dht.readHumidity(); | ||
float temp = dht.readTemperature(); | ||
|
||
if (isnan(hum) || isnan(temp) ){ | ||
Serial.println(F("Failed to read from DHT sensor!")); | ||
return; | ||
} | ||
|
||
Serial.print("Temperature: "); | ||
Serial.print(temp); | ||
Serial.print("°C"); | ||
Serial.print(" Humidity: "); | ||
Serial.print(hum); | ||
Serial.print("%"); | ||
Serial.println(); | ||
|
||
Firebase.setFloat(firebaseData, "/ESP32_APP/TEMPERATURE", temp); | ||
Firebase.setFloat(firebaseData, "/ESP32_APP/HUMIDITY", hum); | ||
delay(200); | ||
} |
Oops, something went wrong.