# Add blocks to generate code
🖥️ Using the IDE
Each tab has a small badge: BLK for a Blocks tab and PY for a Python tab. Both tab types share the same Run, Upload, and Console features.
A small orange dot on a tab means it has unsaved changes. Once a tab has been uploaded to the controller, a colored slot pill appears showing the group letter and slot letter — for example, a red pill reading A-A means Group A (Red), Slot A; a green pill reading B-C means Group B (Green), Slot C. Groups: A=Red, B=Green, C=Blue, D=Yellow. This pill updates when you upload to a different slot and is saved into the file so it restores correctly when you reload the program.
Click Upload to Slot to compile and send the active tab's program to the controller — the launcher restarts automatically and a colored slot pill (e.g. A-B = Group A Red, Slot B) appears on the tab. If the target slot is already occupied by another program, a warning appears before overwriting.
Tip: Upload first, then use Save Blocks — the slot information is embedded in the saved file so when you reload the program later it knows exactly which slot it belongs to.
Group picker phase: All four pixels light up simultaneously in their group colors — Pixel A = Red, B = Green, C = Blue, D = Yellow. Each letter and color identify the same group, so color-blind students can always use the letter instead. Press A, B, C, or D to enter that group (error buzz if the group has no programs).
Slot selection phase: Occupied slots light solid in the group's color; empty slots stay off. Press A, B, C, or D to select an occupied slot — the pixel blinks rapidly to confirm your selection. Press Select to run the program. Press Select without selecting a slot to return to the group picker.
When a program finishes (Code End block), the launcher returns to the group picker automatically. A full slot map of all 16 slots is printed to the console at startup.
titan.* functions — same functions that Blockly generates. File → Save Program saves a .py file; Load Code opens .py files back into a Python tab. Run, Upload, and the Console work identically to Blocks mode.🌾 Control
🤖 Movement
⚙️ Motors
Servos
Sensors
Buttons
💡 Pixels
🔊 Sound
🔁 Loops
while True: in Python. Use this as your main program loop when you want the robot to keep running until it is stopped or reset. Always place sensor reads, decisions, and actions inside a Forever block for continuous operation.break in MicroPython.❓ Logic
🔢 Operators
📝 Variables
try, for, if, while, return, import, class, def, True, False, and None are part of the MicroPython language. If you use one, Blockly will automatically rename it by adding a number (e.g. try becomes try2). Choose descriptive names like counter, distance, or speed instead.🔧 Functions
🐍 Imports & Setup
import titanimport timeimport math, import random.⚙️ Control
titan.Begin()titan.End()Begin() — initialize, wait for Select. Always first.End() — stop motors, return to launcher. Always last.🚗 Movement
setMovementMotors2WD(left, right)setMovementMotors4WD(l1,l2,r1,r2)setMovementSpeed(speed)setMovementWheelDiameter(mm)setMovementWheelbase(mm)moveForDistance(dist, unit, wait)moveBackDistance(dist, unit, wait)startMoving(direction)stopMoving()'cm' or 'rotations'. direction: 'forward'/'backward'.turnDegrees(dir, degrees, wait)imuTurn(dir, degrees, port)startMovingWithSteering(steer)moveWithSteering(steer,dist,unit)'right'/'left'. Steering −100 to +100. imuTurn uses Grove IMU on sensor port.⚡ Motors & Encoders
setMotorSpeed(motor, speed)setMotorSpeeds(s1,s2,s3,s4)setMotorStop(motor, mode)setMotorInvert(motor, True)setMotorTarget(motor, speed, counts)setWheelRotations(motor, rot, speed)waitForMotor(motor)'brake'/'coast'. 2200 counts/rev.getEncoderCount(encoder)resetEncoder(encoder)getMotorBusy(motor)getMotorBusy → True while running to target.🔧 Servos
setServoPosition(servo, angle)setServoPositions(p1,p2,p3,p4)setServoSpeed(servo, speed)setServoInvert(servo, True)getServoPosition(servo)📡 Sensors
getTOFSensor(port, samples)getSonicSensor(port)getLineSensor(port)getColorName(port)getColorSensorIsColor(port,color)getColorRGB(port)getColorHex(port)getReflectedLight(port)isReflectedLight(port,cmp,thresh)getColorHue(port)getColorValue(port)'red','green','blue','white','black','none'. RGB → (r,g,b). Reflected → 0–100.getTHSensor(port, measure, unit)getRotarySensor(port)resetIMUAngle(port)getIMUAngle(port)'temp'/'humid', 'c'/'f'. Rotary → 0–300. IMU → ° since reset.🔘 Buttons
getButtonStatus(button)'select', 'a', 'b', 'c', 'd'.💡 Pixels
setPixelColor(pixel, color, bright)setPixelColorRGB(pixel, r, g, b)setPixelOff(pixel)setPixelBlink(pixel, color, loops)setPixelAnimation(name, duration)'rainbow', 'comet', 'chase', 'fade', 'sparkle'.🔊 Sound
setTone(freq, length)setNote(note, length)setSoundEffect(effect)setSoundOff()'C4', sharps: 'CS4'. Effects: 'siren', 'correct', 'r2d2', 'super_mario' and more.🎨 Color Constants
RED=(255,0,0) YELLOW=(255,150,0)GREEN=(0,255,0) CYAN=(0,255,255)BLUE=(0,0,255) PURPLE=(180,0,255)WHITE=(255,255,255) BLACK=(0,0,0)import titan: titan.setPixelColor('A', RED).