#wokwi orientation - wokwi site, using project URLs, creating a project
# tips - login to be able to save projects; can store code and diagram.json text separately for reuse without logging in
# advanced - saving a project, saving copies, investigating other projects
#initialisation code before main game loop
from time import sleep
from machine import Pin,ADC,PWM
#pico orientation - features, pinout, pin identification (5v/3.3V, GND, analog, digital IO)
# tips - cable colouring conventions: power v ground v data,
# advanced - breadboard wiring
#coding orientatoin
# tips : main loop - before and after while True
# advanced
#initialisation code before main game loop
#connect component potentiometer1 - scale 3000-7000 as int for connection to servo
# tips - analog v digital pin naming conventions: A->ADC->read_u16(),D (Pin.OUT is default, might need Pin.IN)->value()
# extension - replace potentiometer with joystick and use horizontal (HORZ) or vertical (VERT) axis output
p1=ADC(Pin(28,Pin.OUT)) #Pin.OUT is default, not needed
#while True:
# print(int(3000+4000*p1.read_u16()/65536))
# sleep(0.1)
#connect component servo1 - 3 wires, PWM, pulse freq, typically ~1-2ms/50HZ (ie 1-2ms/20ms) PWM range 3000-7000 / 65536
# tips - 'r' to rotate
# extension - servo startup sequence, eg move to center, 2 different positions or sweep through a range
s1=PWM(Pin(0))
s1.freq(50)
dc=3000
#while True:
# s1.duty_u16(int(3000+4000*p1.read_u16()/65536))
# sleep(0.01)
#connect component potentiometer2
# tips -
# extension - replace potentiometer with joystick and use horizontal (HORZ) or vertical (VERT) axis output
#connect component servo2
# tips -
# extension
#connect component - light sensor & score logic
# tips - ? for component documentation, example circuits, tutorials
# extension
ldr=ADC(Pin(26))
#while True:
# print(ldr.read_u16())
# sleep(0.1)
#
# tips -
# extension - connect buzzer as PWM - duty_u16 >0 in on, =0 is off; .freq for pitch (eg 1000-4000)
b=PWM(Pin(18))
b.duty_u16(65000)
for j in range(3):
for i in range(1000,4000):
b.freq(i)
sleep(0.001)
b.duty_u16(0)