Article Index

 

Page 50

from machine import  Pin
pin = Pin(6, Pin.OUT)
while True:
    pin.value(1)
    pin.value(0)
 

Page 51

from machine import  Pin
def flash():
    pin = Pin(2, Pin.OUT)
    while True:
        pin.value(1)
        pin.value(0)
flash()

Page 51

from machine import Pin

@micropython.native
def flash():
    pin = Pin(2, Pin.OUT)
    while True:
        pin.value(1)
        pin.value(0)
flash()

Page 52

from machine import Pin
import time
pin = Pin(2, Pin.OUT)
while True:
    pin.value(1)
    time.sleep(0.5)
    pin.value(0)
    time.sleep(0.5)
 

Page 53

from machine import Pin
import time
pin = Pin(2, Pin.OUT)
while True:
    pin.value(1)
    time.sleep_us(10)
    pin.value(0)
    time.sleep_us(10)

Page 53

from machine import Pin
import time
pin = Pin(2, Pin.OUT)
n = 10
while True:
    for i in range(n):
        pass
    pin.value(1)
    for i in range(n):
        pass
    pin.value(0)

Page 54

from machine import Pin
import time
pin = Pin(2, Pin.OUT)
n = 5
while True:
    t = time.ticks_add(time.ticks_us(), 1000)
    pin.value(1)
    for i in range(n):
        pass

    while time.ticks_us() < t:
        pass
    pin.value(0)

Page 56

import time
from time import sleep
import esp32
from machine import Pin
import machine
pin = Pin(2,Pin.OUT,value=0)
buf = bytearray(b"\x55\x55")
print(buf)
machine.bitstream(pin,0,(80,90,100,110),buf)
 

Page 58

import esp32
from machine import Pin
import machine
pin=Pin(2,Pin.OUT,value=0)
rmt=esp32.RMT(0,pin=pin)
rmt.write_pulses((1000,400,200,300,200,300),1)

Page 59

from machine import Pin

pin1 = Pin(2, Pin.OUT)
pin2 = Pin(4, Pin.OUT)
while True:
    pin1.value(1)
    pin2.value(0)
    pin1.value(0)
    pin2.value(1)

Page 61  

from machine import Pin
import machine

def gpio_set(value, mask):
    machine.mem32[0x3FF44004] = machine.mem32[0x3FF44004] & ~mask | value & mask

pin = Pin(2, Pin.OUT)
pin = Pin(4, Pin.OUT)
value1 = 1 << 2 | 0 << 4
value2 = 0 << 2 | 1 << 4
mask = 1 << 2 | 1 << 4
while True:
    gpio_set(value1, mask)
    gpio_set(value2, mask)