# data[].attributes.body
import event, halo, time
# initialize variables
count = 0
@event.start
def on_start():
global count
halo.led.off_all()
while True:
if halo.pin2.read_digital() == 0:
count = count + 1
halo.led.show_ring('red white white white red red red white white white red red')
halo.led.show_ring('red white white white red red red white white white red red', 3)
time.sleep(2)
else:
halo.led.off_all()
@event.button_pressed
def on_button_pressed():
global count
print(count)

# data[].attributes.headline
Chapter 5 ExternalSensor Activity 2 ProximitySensor

# data[].attributes.subject
Chapter 5 ExternalSensor Activity 2 ProximitySensor

# data[].attributes.body
import event, halo, time

@event.button_pressed

def on_button_pressed():

halo.led.off_all()

while True:

if halo.pin2.read_digital() == 0:

for count in range(1):

halo.led.show_ring('red white white white red red red white white white red red')

halo.led.show_ring('red white white white red red red white white white red red', 3)

else:

halo.led.off_all()

# data[].attributes.headline
Chapter 5 ExternalSensor Activity 1 MoistureDetector

# data[].attributes.subject
Chapter 5 ExternalSensor Activity 1 MoistureDetector

# data[].attributes.body
import event, halo, time

@event.button_pressed

def on_button_pressed():

halo.led.off_all()

while halo.pin2.read_analog() > 0:

if halo.pin2.read_analog() < 974:

halo.led.show_single(7, 255, 0, 0)

if halo.pin2.read_analog() < 500:

halo.led.show_single(6, 0, 0, 255)

halo.led.show_single(8, 0, 0, 255)

if halo.pin2.read_analog() < 90:

halo.led.show_single(5, 0, 255, 0)

halo.led.show_single(9, 0, 255, 0)

if halo.pin2.read_analog() < 80:

halo.led.show_single(4, 100, 0 ,255)

halo.led.show_single(10, 100, 0 ,255)

if halo.pin2.read_analog() < 70:

halo.led.show_single(3, 0, 100, 50)

halo.led.show_single(11, 0, 100, 50)

else:

halo.led.off_all()

print(halo.pin2.read_analog())

# data[].attributes.headline
Chapter 4 ServoMotor Activity 2 WindscreenWiper

# data[].attributes.subject
Chapter 4 ServoMotor Activity 2 WindscreenWiper

# data[].attributes.body
# generated by mBlock5 for HaloCode

# codes make you happy

import event, halo, time

# initialize variables

WiperSpeed = 0

@event.start

def on_start():

global WiperSpeed

WiperSpeed = 2

while True:

if WiperSpeed == 0:

WiperSpeed = 2

halo.pin0.servo_write(0)

time.sleep(float(WiperSpeed))

halo.pin0.servo_write(180)

time.sleep(float(WiperSpeed))

@event.button_pressed

def on_button_pressed():

global WiperSpeed

WiperSpeed = WiperSpeed - 0.5

# data[].attributes.headline
Chapter 4 ServoMotor Activity 1 ServoTouch

# data[].attributes.subject
Chapter 4 ServoMotor Activity 1 ServoTouch

# data[].attributes.body
# generated by mBlock5 for HaloCode

# codes make you happy

import event, halo, time

@event.start

def on_start():

while True:

if halo.touchpad1.is_touched():

halo.pin0.servo_write(0)

if halo.touchpad2.is_touched():

halo.pin0.servo_write(180)

# data[].attributes.headline
Chapter 3 Actuators Challenge JumpCounterV2

# data[].attributes.subject
Chapter 3 Actuators Challenge JumpCounterV2

# data[].attributes.body
import event, halo, time

# initialize variables

jump_count = 0

rounds = 0

@event.start

def on_start():

global jump_count, rounds

jump_count = 0

rounds = 1

while True:

if jump_count == 12 and rounds == 3:

jump_count = 0

rounds = 1

if jump_count == 12:

rounds = rounds + 1

jump_count = 0

while not halo.motion_sensor.is_shaked():

pass

jump_count = jump_count + 1

if rounds == 1:

halo.led.show_single(jump_count, 255, 0, 0)

if rounds == 2:

halo.led.show_single(jump_count, 0, 255, 0)

if rounds == 3:

halo.led.show_single(jump_count, 0, 0, 255)

time.sleep(1)

# data[].attributes.headline
Chapter 3 Actuators Activity 2 Jump Counter

# data[].attributes.subject
Chapter 3 Actuators Activity 2 Jump Counter

# data[].attributes.body
# generated by mBlock5 for HaloCode

# codes make you happy

import event, halo, time

@event.start

def on_start():

global jump_count

jump_count = 0

while True:

while not halo.motion_sensor.is_shaked():

pass

jump_count = jump_count + 1

halo.led.show_single(jump_count, 255, 0, 0)

time.sleep(1)

# data[].attributes.headline
Chapter 3 Actuators Activity 1 Tilt Smile

# data[].attributes.subject
Chapter 3 Actuators Activity 1 Tilt Smile

# data[].attributes.body
# generated by mBlock5 for HaloCode

# codes make you happy

import event, halo, time

@event.start

def on_start():

while True:

if halo.motion_sensor.get_pitch() > 70:

halo.led.show_ring('yellow black black yellow yellow yellow yellow yellow black black yellow black')

else:

halo.led.off_all()

# data[].attributes.body
import event, halo, time

@event.start

def on_start():

halo.led.show_animation('rainbow')

# data[].attributes.body
# generated by mBlock5 for HaloCode

# codes make you happy

import event, halo, time

@event.start

def on_start():

halo.led.show_single(1, 0, 0, 255)

halo.led.show_single(2, 0, 255, 0)

halo.led.show_single(3, 255, 255, 255)

halo.led.show_single(4, 255, 0, 0)

halo.led.show_single(5, 0, 0, 255)

halo.led.show_single(6, 0, 255, 0)

halo.led.show_single(7, 255, 255, 255)

halo.led.show_single(8, 255, 0, 0)

halo.led.show_single(9, 0, 0, 255)

halo.led.show_single(10, 0, 255, 0)

halo.led.show_single(11, 255, 255, 255)

halo.led.show_single(12, 255, 0, 0)

# data[].attributes.body
import event, halo, time

@event.start

def on_start():

global count

count = 0

while True:

count = count + 1

halo.led.show_single(count, 255, 0, 0)

time.sleep(1)

# data[].attributes.body
import event, halo, time, random

@event.start

def on_start():

global count

count = 12

red = 0

green = 0

blue = 0

while True:

red = random.randint(0, 255)

green = random.randint(0, 255)

blue = random.randint(0, 255)

halo.led.show_single(count, red, green, blue)

count = count - 1

time.sleep(1)

# data[].attributes.body
import event, halo, time, random

@event.start

def on_start():

global count

count = 0

red = 0

green = 0

blue = 0

while True:

count = count + 1

red = random.randint(0, 255)

green = random.randint(0, 255)

blue = random.randint(0, 255)

halo.led.show_single(count, red, green, blue)

time.sleep(1)

# data[].attributes.body
import event, halo, time

@event.start

def on_start():

while True:

if halo.button.is_pressed():

halo.led.show_all(255, 0, 0)

time.sleep(1)

halo.led.off_all()

time.sleep(1)

if halo.touchpad0.is_touched():

halo.led.show_all(0, 0, 255)

if halo.touchpad1.is_touched():

halo.led.show_all(0, 255, 0)

if halo.touchpad2.is_touched():

halo.led.show_all(255, 0, 255)

if halo.touchpad3.is_touched():

halo.led.show_all(0, 255, 255)

# data[].attributes.body
import event, halo, time

@event.start

def on_start():

while True:

if halo.motion_sensor.is_tilted_left():

left_rainbow()

if halo.motion_sensor.is_tilted_right():

right_rainbow()

if halo.motion_sensor.is_arrow_up():

up_rainbow()

if halo.motion_sensor.is_arrow_down():

down_rainbow()

def left_rainbow ():

halo.led.show_ring('black black black black black purple blue cyan green yellow orange red')

def right_rainbow ():

halo.led.show_ring('orange yellow green cyan blue purple black black black black black red')

def up_rainbow ():

halo.led.show_ring('black black blue green orange red yellow cyan purple black black black')

def down_rainbow ():

halo.led.show_ring('orange green blue black black black black black purple cyan yellow red')

# data[].attributes.body
import event, halo, time

@event.start

def on_start():

while True:

if halo.touchpad0.is_touched():

if halo.touchpad0.get_value() > 90:

strong()

if halo.touchpad0.get_value() < 90:

weak()

def strong():

halo.led.show_all(255, 0,0)

time.sleep(1)

halo.led.off_all()

time.sleep(1)

def weak():

halo.led.show_all(0, 0,255)

time.sleep(1)

halo.led.off_all()

time.sleep(1)