Skip to content

waiweng83/micropython-rekabit

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 

Repository files navigation

Python editor for micro:bit

Step 1: Open Python Editor

Open Python editor at: https://python.microbit.org/v/3

Step 2: Add module

Download MicroPython module from GitHub: https://github.com/Bhavithiran97/micropython-rekabit

Click on the Project button in the editor 1

Click Open and Add file button

2

Add rekabit.py to the editor 3

Neopixel

  • This kit has 2 NeoPixels (WS2812B programmable RGB LEDs) built-in.
  • REKA:BIT's built-in neopixel works with the default neopixel module that comes with MicroPython on the BBC micro:bit.
  • Use import neopixel at the top of your program

Create a NeoPixel strip at pin P8 with 2 LEDs

import neopixel
np = neopixel.NeoPixel(pin8, 2)

Show color red on all RGB pixels

import neopixel
np = neopixel.NeoPixel(pin8, 2)
for LED in range(2):
	np[LED] = (255,0,0)
np.show()

Show specific color on each RGB pixels

import neopixel
np = neopixel.NeoPixel(pin8, 2)
#rainbow color
np[0]= 255,0,0    #red
np[1]= 255,255,0  #yellow

clear all RGB pixels

np.clear()

RGB values for commonly used colors

  • red = 255,0,0
  • orange = 255,164,0
  • yellow = 255,255,0
  • green = 0,255,0
  • blue = 0,0,255
  • indigo = 75,0,130
  • violet = 138,43,226
  • purple = 255,0,255
  • white = 255,255,255
  • black = 0,0,0

Find more information about Neopixel's MicroPython module here: https://microbit-micropython.readthedocs.io/en/latest/neopixel.html#module-neopixel

Music

  • REKA:BIT's built-in piezo buzzer works with the default music module that comes with MicroPython on the BBC micro:bit.
  • Use import music at the top of your program

Play built-in melodies

import music
music.play(music.DADADADUM)

Play custom notes

import music
#starting tune of "Twinkle Twinkle Little Star"
tune=["C4:1","C4:1","G4:1","G4:1","A4:1","A4:1","G4:1"]
music.set_tempo(ticks=2)
music.play(tune)

Find more information about music MicroPython module here: https://microbit-micropython.readthedocs.io/en/latest/music.html

⚠️ Add these lines for the following modules

Use from rekabit import * at the top of your program - Use init() inside a while True loop to monitor the power switch and reset microbit when power cycled.

Digital IO

Read digital pin 9

from rekabit import *

while True:
    init()
    if pin9.read_digital():
        display.show(Image.HAPPY)
    else:
        display.show(Image.SAD)

Write digital on pin 12

from rekabit import *

while True:
    init()
    pin12.write_digital(1)
    sleep(20)
    pin12.write_digital(0)
    sleep(480)

Find more information about analog MicroPython module here: https://microbit-micropython.readthedocs.io/en/v1.0.1/pin.html#module-microbit

Analog IO

Read analog pin 1

from rekabit import *

while True:
    init()
    if pin1.read_analog() > 500:
        display.show(Image.HAPPY)
    else:
        display.show(Image.SAD)

Write analog on pin 2

from rekabit import *

while True:
    init()
    pin12.write_analog(511)

Find more information about analog MicroPython module here: https://microbit-micropython.readthedocs.io/en/v1.0.1/pin.html#pulse-width-modulation

DC Motors

Run Motor 1 forward at 50% speed when button A is pressed, brake the motor when button B is pressed.

from rekabit import *
while True:
	init()
	if button_a.is_pressed():
		run_motor(M1,Forward, speed=128 )
	elif button_b.is_pressed():
		brake_motor(M1)

Servos

Rotate Servo 1 to 0 degree when button A is pressed, rotate Servo 1 to 180 degrees when button B is pressed, disable Servo 1 when button A+B pressed

from rekabit import *
while True:
	init()
	if button_a.is_pressed() and button_b.is_pressed():
		disable_servo(S1)
	elif button_a.is_pressed():
		sets_servo_position(S1, position=0 )
	elif button_b.is_pressed():
		sets_servo_position(S1, position=180 )

Power

Show power input voltage

from rekabit import *
while True:
	init()
	display.scroll(read_Vin())

Show sad face if the voltage is low

from rekabit import *
while True:
	init()
	if is_low_batt():
		display.show(Image.SAD)

Show sad face if over voltage

from rekabit import *
while True:
	init()
	if is_overvoltage():
		display.show(Image.SAD)

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%