MicroPython Codes of the PicoBricks
from machine import Pin,ADC,PWM#to access the hardware on the pico
from utime import sleep #time library
ldr=ADC(27) #initialize digital pin 27forLDR
servo=PWM(Pin(21)) #initialize digital PWM pin 27for Servo Motor
servo.freq(50)while True:sleep(0.01)
#When LDR data higher than 40000if ldr.read_u16()>4000:
servo.duty_u16(2000)# sets position to 180 degrees
sleep(0.1)#delay
servo.duty_u16(1350) # sets position to 0 degrees
sleep(0.5)#delay
Arduino C Codes of the PicoBricks
#include
Servo myservo;voidsetup(){// put your setup code here, to run once:
myservo.attach(22);
myservo.write(20);pinMode(27,INPUT);}voidloop(){// put your main code here, to run repeatedly:
int light_sensor=analogRead(27);if(light_sensor>100){
int x=45;
int y=20;
myservo.write(x);delay(100);
myservo.write(y);delay(500);}}
GitHub Project Page
Tags: