Code Kitty Function Reference                                         version 2.0

By the Code Kitty Team (info@codekitty.org)

Note: You must bring in all codekitty functions by starting your code with:
from codekitty import *

Output Functions

How it’s used

Driving Functions (bolded variables are required, others are optional)

go(time, speed)

Drives the kitty forward for time seconds. This can be expressed as a decimal (.5) or Integer (1) variable.

Speed variables are “slow” or “fast” (optional). Default is “fast”.

left(degrees)

Turns the kitty left 45 or 90 degrees.

right(degrees)

Turns the kitty left 45 or 90 degrees.

back(time, speed)

Drives the kitty backward for time seconds. This can be expressed as a decimal (.5) or Integer (1) variable.

Speed variables are “slow” or “fast” (optional). Default is “fast”.

stop()

Stops the kitty’s motors

LED Functions

led(color)

Turns on the kitty’s  LED. Variables are “red”, “orange”, “yellow”, “green”, “blue”, “purple”, “pink”,”off”.

rainbow()

Goes into an endless loop alternating between all the colors of the rainbow. Press ctrl-c to stop it.

Sound Functions

beep()

Does a beep! (Note is E above Middle-C)

note(note, duration)

Plays a single music note.  Argument is the note, like “c4” for Middle-C.  You need the quotes and it is case sensitive.

Duration:
1 = whole note

2 = half note

4 = quarter note

8 = eighth note

march()

Plays code kitty’s favorite song,

Input Values

How it’s used

Sensor

sensor.value

Returns a number. Typically a high number (ie 65536) if it doesn’t detect anything, and a lower number (< 6000) if it detects something.

Example code:

while (True):

if(sensor.value < 6000):

print(“Object detected”)

else:

print(“Nothing detected nearby”)

The above code is an endless loop that prints “Object detected” anytime an object is detected near the sensor.  Note that sensor values will vary depending on the sensor attachment you’re using! Code Kitty’s default sensor is typically between 0 - 65536 (no object nearby).  

Touch

touch.value

Returns a boolean values (True/False).

Example code:

Comments:

from codekitty import *

list = [“C4”, “F3”, “D5”, “B4”]

for x in list:

    note (x, 4)

    go (1)

    left (90)  

#must do this first to import Code Kitty specific functions

#defining the variable “list” with 4 different note names

#start a loop to play the first note in quarter note duration, drive #forward, and turn.. Then play the 2nd note, drive forward, and turn…

#by the end of the loop you will have played 4 notes, driven forward 4 #times, and turned in (approximately) a circle.

Another useful Python function (bolded variables are required)

sleep(time)

Delays your program for time seconds.  Can use decimals (e.g. 0.5).

Import with:

from time import sleep

Use with:

sleep(1)