print("HELLO, THIS MINI PROJECT")
print("Date : 16/01/2024")
print("BY : ")
#Import all recessary libraries
from machine import Pin, PWM, ADC, SoftI2C
from utime import sleep
import library_servo_motor
import ssd1306
#Pin declaration
buzzer = PWM(Pin (27), Pin.OUT)
SERVO_PIN = Pin(14, Pin.OUT)
LDR_Pin = ADC(Pin(2, Pin.IN))
led_red = Pin(18, Pin.OUT)
led_blue = Pin(5, Pin.OUT)
i2c_oled = SoftI2C(scl=Pin(22), sda=Pin(21))
oled_width = 128
oled_height = 64
#Create the object name for sensor with library ---> LIBRARYNAME.CLASSNAME (classname amik dlm library)
gate_motor = library_servo_motor.Servo(pin=SERVO_PIN)
skrin =ssd1306.SSD1306_I2C(width=oled_width, height=oled_height, i2c=i2c_oled) #library name.class name()
#Main Program
while True :
kecerahan_cahaya = LDR_Pin.read()
voltage = kecerahan_cahaya/ 4096 * 5.0
print('The voltage detected is :' , voltage, 'V')
#SERVO MOTOR PART AND OLED
if 3< voltage <5:
led_red.on()
sleep(0.5)
led_red.off()
sleep(0.1)
led_blue.off()
sleep(0.3)
buzzer.init(freq=8670,duty=700)
sleep(0.4)
buzzer.init(freq=1,duty=0)
sleep(0.2)
gate_motor.move(0)
sleep(0)
gate_motor.move(90)
sleep(5)
skrin.fill(1) #1 is code WHITE , 0 is code BLACK
skrin.text('RAINY DAY', 1, 10,0 ) #Text, column, row , colour
skrin.text('CLOSE THE ROOF', 1, 20, 0 )
skrin.show()
else :
led_blue.on()
sleep(0.5)
led_blue.off()
sleep(0.1)
led_red.off()
sleep(0.1)
buzzer.init(freq=1,duty=0)
sleep(2)
gate_motor.move(0)
sleep(0)
skrin.fill(1) #1 is code WHITE , 0 is code BLACK
skrin.text('GOOD WEATHER ^_^', 1, 10,0 ) #Text, column, row , colour
skrin.text('OPEN THE ROOF', 2, 20,0 )
skrin.show()
#LED PART
# if 3< voltage <5:
# for u in range (10):
# led_red.on()
# sleep(0.2)
# led_red.off()
# sleep(0.3)
# led_blue.off()
# sleep(0.3)
# else :
# led_blue.on()
# sleep(1)
# led_red.off()
# sleep(0.3)
sleep(2)