Enrico Miglino
Published © CC BY-NC-SA

Birds

A STEM interactive animated project for BBC micro:bit part of the Art-a-Tronic interactive art project.

IntermediateFull instructions provided10 hours1,987
Birds

Things used in this project

Hardware components

BBC micro:bit board
BBC micro:bit board
×1
kitroniAll-in-one robotic control board for BBC micro:bit
×1
SG90 Micro-servo motor
SG90 Micro-servo motor
×1

Software apps and online services

MakeCode
Microsoft MakeCode

Hand tools and fabrication machines

Laser cutter (generic)
Laser cutter (generic)

Story

Read more

Custom parts and enclosures

SVG Files

The design SVG (Inkscape) files used to laser-cut the components

Code

Birds.js

JavaScript
The program exported in Java, created with makecode for the BBC micro:bit
let increment = 0
let maxBird: number[] = []
let trigAcceleration = 0
let birdDirection: number[] = []
let stepBirdAngle: number[] = []
let birdPosition: number[] = []
let BirdMoveDelay = 0
function moveBirds() {
    Kitronik_Robotics_Board.servoWrite(Kitronik_Robotics_Board.Servos.Servo4, birdPosition[0])
    Kitronik_Robotics_Board.servoWrite(Kitronik_Robotics_Board.Servos.Servo5, birdPosition[1])
    Kitronik_Robotics_Board.servoWrite(Kitronik_Robotics_Board.Servos.Servo6, birdPosition[2])
    Kitronik_Robotics_Board.servoWrite(Kitronik_Robotics_Board.Servos.Servo7, birdPosition[3])
    Kitronik_Robotics_Board.servoWrite(Kitronik_Robotics_Board.Servos.Servo8, birdPosition[4])
    for (let index = 0; index <= 4; index++) {
        increment = stepBirdAngle[index] * birdDirection[index]
        birdPosition[index] = birdPosition[index] + increment
        if (birdPosition[index] < 0) {
            birdDirection[index] = -1 * birdDirection[index]
            birdPosition[index] = 0
        }
        if (birdPosition[index] > maxBird[index]) {
            birdDirection[index] = -1 * birdDirection[index]
            birdPosition[index] = maxBird[index]
        }
        basic.pause(BirdMoveDelay)
    }
}
function startTwitters2() {
    Kitronik_Robotics_Board.servoWrite(Kitronik_Robotics_Board.Servos.Servo1, 20)
    Kitronik_Robotics_Board.servoWrite(Kitronik_Robotics_Board.Servos.Servo2, 170)
    Kitronik_Robotics_Board.servoWrite(Kitronik_Robotics_Board.Servos.Servo3, 160)
}
Kitronik_Robotics_Board.allOff()
BirdMoveDelay = 5
stepBirdAngle = [1, 3, 2, 2, 5]
birdDirection = [-1, -1, -1, -1, -1]
birdPosition = [45, 70, 80, 60, 90]
maxBird = [80, 70, 90, 60, 90]
trigAcceleration = 1018
basic.forever(function () {
    led.enable(true)
    basic.showIcon(IconNames.Duck)
    if (input.acceleration(Dimension.Strength) <= trigAcceleration) {
        startTwitters2()
        for (let i = 0; i < 500; i++) {
            moveBirds()
        }
        Kitronik_Robotics_Board.allOff()
    }
    led.enable(false)
})

Credits

Enrico Miglino

Enrico Miglino

4 projects • 20 followers
Software and hardware developer, designer and photographer, maker and (maybe) inventor. I work on Windows, iOS, Android, Linux, MCUs

Comments