Sunday 18 December 2016

4Tronix Bit:Bot - now there is a good idea.

When I first heard of this robot, my first thought was what a great idea; a robot with neopixels (I know I should be saying 'smart RGB LEDs' but neopixels is so much more snappier) controlled via a micro:bit.





A good starting point for learning more about this robot, is the details on the 4Tronix site/blog, which includes build guidance and programming instructions for micropython and PXT. Though for the micropython code you might need to change pinX.digital_write() to pinX.write_digital() where X is the pin number.

My play code was to randomly select which neopixels to light up, I didn't include code to turn them off so multiple ones can be on. The robot is driven forwards, waits, backward, waits, turns to the right and then the left; and then repeats. 

Code:
from microbit import *
import neopixel, random

np = neopixel.NeoPixel(pin13, 12)

def forward(n):
    pin0.write_digital(1)
    pin8.write_digital(0) 
    pin1.write_digital(1)
    pin12.write_digital(0)
    sleep(n*1000)
    
def halt(n):
    pin0.write_digital(0)
    pin8.write_digital(0)
    pin1.write_digital(0)
    pin12.write_digital(0)
    sleep(n*1000)
    
def backward(n):
    pin0.write_digital(0)
    pin8.write_digital(1) 
    pin1.write_digital(0)
    pin12.write_digital(1)
    sleep(n*1000)

def right_turn(n):
    pin0.write_digital(1)
    pin8.write_digital(0) 
    pin1.write_digital(0)
    pin12.write_digital(1)
    sleep(n*1000)

def left_turn(n):
    pin0.write_digital(0)
    pin8.write_digital(1) 
    pin1.write_digital(1)
    pin12.write_digital(0)
    sleep(n*1000)

while True:
    pxl=random.randint(1,11)
    rd=random.randint(1,32)
    gr=random.randint(1,32)
    bl=random.randint(1,32)
    t1=random.randint(10,100)
    np[pxl] = (rd, gr, bl)
    np.show()
    forward(1)
    halt(1)
    backward(1)
    halt(1)
    right_turn(1)

    left_turn(1)

The video below shows it in action, the code is simple but this is a lovely robot to program especially if the mu editor is used.




All opinions in this blog are the Author's and should not in any way be seen as reflecting the views of any organisation the Author has any association with. Twitter @scottturneruon

1 comment:

  1. This comment has been removed by a blog administrator.

    ReplyDelete

Top posts on this blog in March 2024

The Top 10 viewed post on this blog in March 2024. Covering areas such as small robots, augmented reality, Scratch programming, robots. Micr...