print('\n\nThis program is to measure height requirement for roller coaster\n')
print('Date : 04/12/2023')
print('By : AKMAL FAIZ\n')
#Import all necessary libraries
from machine import Pin,SoftI2C,PWM
from utime import sleep
import Servo
import Ultrasonic
import ssd1306 #This is OLED Library
#Pin Declaration (nama parameter mesti kena ada underscore)
led_red = Pin(2, Pin.OUT)
PIR_Sensor = Pin(13, Pin.IN)
Trig = Pin(25, Pin.IN) #Ultrasonic
Echo = Pin(27, Pin.OUT) #Ultrasonic
servo = Pin(14, Pin.OUT)
buzzer = PWM(Pin(26), Pin.OUT)
i2c_oled = SoftI2C(scl=Pin(22), sda=Pin(21))
oled_width = 128
oled_height = 64
#Parameter declaration
counter = 1
limit = 3
#Create the object name for sensor with library --> LIBRARYNAME.CLASSNAME
#bagi nama = Import Library Name.Class Name (trigger_pin, echo_pin,)
sonic = Ultrasonic.HCSR04(trigger_pin=Trig, echo_pin=Echo)
gate = Servo.Servo(pin=servo)
screen = ssd1306.SSD1306_I2C(width=oled_width, height=oled_height, i2c=i2c_oled) #library name.class name()
#Main Program
while True: #endless repeating
status_of_pir = PIR_Sensor.value() #The value will be 0 or 1
#OLED PART
screen.fill(1)
screen.text("Roller Coaster",5,10,0) #Text, Column, Colour code
screen.text("Height",30,25,0) #Text, Column, Colour code
screen.text("Requirement",20,40,0) #Text, Column, Colour code
screen.show()
sleep(4)
#ULTRASONIC PART
led_red.on()
sleep(.2)
print("\n===== Jom Check Ketinggian Anda dalam CM ====")
sleep(2)
distance_in_cm = sonic.distance_cm() #parameter(create your own name) = bagi nama.function(define)
print("Ketinggian anda dalam CM : ", distance_in_cm, "cm") #print,parameter(Create your own name)
if distance_in_cm <=100: #Palang akan bukak
for u in range (1):
gate.move(90) #Palang masih tutup
sleep(1)
gate.move(0) #Palang akan bukak
sleep(1)
print("Bilangan penunggang sekarang =", counter)
elif (counter = counter < limit):
print "Counter is {} and Limit is {}.".format(Counter, Limit)
print "Adding {} to to Counter.".format(AddValue)
Counter = Counter + AddValue
print "The counter has met or exceeded the limit."
print "Counter = {}, Limit = {}".format(Counter, Limit)
buzzer.init(freq=1000, duty=1023) #(adjust bunyi,adjust duration0-1023)
sleep(0.5)
buzzer.init(freq=1, duty=10)
sleep(0.5)
gate.move(90) #Palang tutup semula
sleep(1)
while Counter < Limit:
# elif counter = 5:
# print('Hey! Motion detected!')
# counter = counter-2
else:
gate.move(90)
for i in range (10):
buzzer.init(freq=1000, duty=200) #(adjust bunyi,adjust duration)
sleep(0.1)
buzzer.init(freq=1, duty=10)
sleep(0.1)
led_red.off()
sleep(.2)