Skip to content
Snippets Groups Projects
Commit 3656a6ab authored by Muhamad Irfan Maulana's avatar Muhamad Irfan Maulana
Browse files

add 7-segment

parents 3b5e41b2 7febd056
No related merge requests found
// pin 11 of 74HC595 (SHCP)
const int bit_clock_pin = 13;
// pin 12 of 74HC595 (STCP)
const int digit_clock_pin = 12;
// pin 14 of 74HC595 (DS)
const int data_pin = 11;
// digit pattern for a 7-segment display
const byte digit_pattern[10] =
{
B00111111, // 0
B00000110, // 1
B01011011, // 2
B01001111, // 3
B01100110, // 4
B01101101, // 5
B01111101, // 6
B00000111, // 7
B01111111, // 8
B01101111, // 9
};
unsigned int counter = 0;
void setup()
{
pinMode(data_pin, OUTPUT);
pinMode(bit_clock_pin, OUTPUT);
pinMode(digit_clock_pin, OUTPUT);
}
void update_one_digit(int data)
{
int i;
byte pattern;
// get the digit pattern to be updated
pattern = digit_pattern[data];
// turn off the output of 74HC595
digitalWrite(digit_clock_pin, LOW);
// update data pattern to be outputed from 74HC595
// because it's a common anode LED, the pattern needs to be inverted
shiftOut(data_pin, bit_clock_pin, MSBFIRST, ~pattern);
// turn on the output of 74HC595
digitalWrite(digit_clock_pin, HIGH);
}
void loop()
{
int i;
unsigned int digit_base;
counter++;
digit_base = 10;
// get the value to be displayed and update one digit
update_one_digit(counter % digit_base);
delay(500);
}
const int ledPin = 2;
const int buttonPin = 4;
int buttonState = 0;
int val = 0;
int soilPin = A0;
int soilPower = 7;
int statusLED = 0;
int buzzer = 9;
int buzzerHigh = false;
int sensorLDR = A1;
int valueLDR = 0;
int res0 = 10.0;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(buttonPin, INPUT);
pinMode(ledPin, OUTPUT);
pinMode(soilPower, OUTPUT);
pinMode(buzzer, OUTPUT);
digitalWrite(soilPower, LOW);
}
void loop() {
// put your main code here, to run repeatedly:
buttonState = digitalRead(buttonPin);
if(buttonState == HIGH) {
digitalWrite(buzzer, LOW);
Serial.println("botton clicked");
}
Serial.print("Soil Moisture = ");
Serial.println(readSoil());
if (readSoil() > 50) {
Serial.println("wet soil");
digitalWrite(ledPin, LOW);
} else {
Serial.println("dry soil");
digitalWrite(ledPin, HIGH);
digitalWrite(buzzer, HIGH);
Serial.println("alarm on");
}
valueLDR = analogRead(sensorLDR); // read the value from the sensor
Serial.print("cahaya: "); //prints the values coming from the sensor on the screen
float vout0 = valueLDR*0.0048828125; // calculate the voltage
int lux0 = 500/(res0*((5-vout0)/vout0)); // calculate the Lux
Serial.println(lux0);
// delay(1000); //​take a reading every second
}
int readSoil() {
// digitalWrite(soilPower, HIGH);​ //turn D7 "On"
digitalWrite(soilPower, HIGH);
delay(10);
val = analogRead(soilPin);
digitalWrite(soilPower, LOW);
return 1023-val; //send current moisture value
}
......@@ -48,12 +48,13 @@ void ReadJson() {
char* GenerateJSONString() {
char buff[12];
char* totalString, ageText, humidityText, lightText, yearString, humidityString, lightString;
yearString = itoa(year,buff,10);
humidityString = itoa(humidity,buff,10);
lightString = itoa(light,buff,10);
ageText = "age : ";
//yearString = itoa(year,buff,10);
//humidityString = itoa(humidity,buff,10);
//lightString = "12";
//lightString = itoa(light,buff,10);
//ageText = "age : ";
totalString = "|age : ", yearString, " humidity : ", humidityString, " light : ", lightString, "|";
totalString = "|age : ";//, yearString, " humidity : ", humidityString, " light : ";//, lightString, "|";
return (totalString);
}
......@@ -2,19 +2,19 @@
#include <LiquidCrystal_I2C.h>
// Set the LCD address to 0x27 for a 16 chars and 2 line display
LiquidCrystal_I2C lcd(0x3F,16,2);
LiquidCrystal_I2C lcd(0x3F, 16, 2);
void setup()
{
// initialize the LCD
lcd.init();
// initialize the LCD
lcd.init();
// Turn on the blacklight and print a message.
lcd.backlight();
lcd.print("Hello, world!");
// Turn on the blacklight and print a message.
lcd.backlight();
lcd.print("Hello, world!");
}
void loop()
{
// Do nothing here...
}
// Do nothing here...
}
\ No newline at end of file
File added
#include <HttpClient.h>
const int ledPin = 2;
const int buttonPin = 4;
int buttonState = 0;
......@@ -7,7 +9,10 @@ int soilPower = 7;
int statusLED = 0;
int buzzer = 9;
int buzzerHigh = false;
int sensorLDR = A1;
int valueLDR = 0;
int res0 = 10.0;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
......@@ -40,7 +45,12 @@ void loop() {
Serial.println("alarm on");
}
// delay(1000); //​take a reading every second
valueLDR = analogRead(sensorLDR); // read the value from the sensor
Serial.print("cahaya: "); //prints the values coming from the sensor on the screen
float vout0 = valueLDR*0.0048828125; // calculate the voltage
int lux0 = 500/(res0*((5-vout0)/vout0)); // calculate the Lux
Serial.println(lux0);
delay(1000); //​take a reading every second
}
int readSoil() {
......
#include <HttpClient.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
const int ledPin = 2;
const int buttonPin = 4;
int buttonState = 0;
int val = 0;
int soilPin = A0;
int soilPower = 7;
int statusLED = 0;
int buzzer = 9;
int buzzerHigh = false;
int sensorLDR = A1;
int valueLDR = 0;
int res0 = 10.0;
// Set the LCD address to 0x27 for a 16 chars and 2 line display
LiquidCrystal_I2C lcd(0x3F, 16, 2);
// pin 11 of 74HC595 (SHCP)
const int bit_clock_pin = 13;
// pin 12 of 74HC595 (STCP)
const int digit_clock_pin = 12;
// pin 14 of 74HC595 (DS)
const int data_pin = 11;
// digit pattern for a 7-segment display
const byte digit_pattern[10] =
{
B00111111, // 0
B00000110, // 1
B01011011, // 2
B01001111, // 3
B01100110, // 4
B01101101, // 5
B01111101, // 6
B00000111, // 7
B01111111, // 8
B01101111, // 9
};
unsigned int counter = 0;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(buttonPin, INPUT);
pinMode(ledPin, OUTPUT);
pinMode(soilPower, OUTPUT);
pinMode(buzzer, OUTPUT);
digitalWrite(soilPower, LOW);
pinMode(data_pin, OUTPUT);
pinMode(bit_clock_pin, OUTPUT);
pinMode(digit_clock_pin, OUTPUT);
// initialize the LCD
lcd.init();
// Turn on the blacklight and print a message.
lcd.backlight();
}
void loop() {
int i;
unsigned int digit_base;
counter++;
digit_base = 10;
// get the value to be displayed and update one digit
update_one_digit(counter % digit_base);
lcd.setCursor(0,0);
lcd.autoscroll();
lcd.print("Hello! Welcome to GreenTyNo :)");
delay(1000);
// put your main code here, to run repeatedly:
buttonState = digitalRead(buttonPin);
if(buttonState == HIGH) {
buzzerHigh = false;
}
Serial.print("Soil Moisture = ");
Serial.println(readSoil());
if (readSoil() > 60) {
Serial.println("wet soil");
digitalWrite(ledPin, LOW);
} else {
Serial.println("dry soil");
digitalWrite(ledPin, HIGH);
// digitalWrite(buzzer, HIGH);
// delay(200);
// digitalWrite(buzzer, LOW);
// delay(1000);
buzzerHigh = true;
Serial.println("alarm on");
}
if(buzzerHigh) {
digitalWrite(buzzer, HIGH);
delay(200);
digitalWrite(buzzer, LOW);
delay(1000);
}
valueLDR = analogRead(sensorLDR); // read the value from the sensor
Serial.print("cahaya: "); //prints the values coming from the sensor on the screen
float vout0 = valueLDR*0.0048828125; // calculate the voltage
int lux0 = 500/(res0*((5-vout0)/vout0)); // calculate the Lux
Serial.println(lux0);
// delay(1000); //​take a reading every second
}
int readSoil() {
// digitalWrite(soilPower, HIGH);​ //turn D7 "On"
digitalWrite(soilPower, HIGH);
delay(10);
val = analogRead(soilPin);
digitalWrite(soilPower, LOW);
return 1023-val; //send current moisture value
}
void update_one_digit(int data)
{
int i;
byte pattern;
// get the digit pattern to be updated
pattern = digit_pattern[data];
// turn off the output of 74HC595
digitalWrite(digit_clock_pin, LOW);
// update data pattern to be outputed from 74HC595
// because it's a common anode LED, the pattern needs to be inverted
shiftOut(data_pin, bit_clock_pin, MSBFIRST, ~pattern);
// turn on the output of 74HC595
digitalWrite(digit_clock_pin, HIGH);
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment