EVR.Level.Delegate = function(level)
{
   this.level = level;
   this.evr = level.evr;
   this.prompt = level.prompt;
   this.countdown = level.countdown;
   this.racer = level.road.racer;
   this.path = level.road.path;
}
EVR.Level.Delegate.prototype.enter = function()
{
   var level = this.level;
   var prompt = this.prompt;
   if (level.states[LEVEL_STATE_WAITING])
   {
      prompt.remove();
      this.countdown.start();
      prompt.set_text(LEVEL_PAUSE_PROMPT_TEXT);
   }
   else if (level.states[LEVEL_STATE_RACING])
   {
      level.pause();
   }
   else if (level.states[LEVEL_STATE_SUMMARIZING])
   {
      level.show_records();
   }
   else if (level.states[LEVEL_STATE_FINISHED])
   {
      prompt.set_finish_text();
      prompt.toggle();
   }
}
EVR.Level.Delegate.prototype.up = function()
{
   if (this.path.playing)
   {
      this.racer.move(-1);
   }
}
EVR.Level.Delegate.prototype.down = function()
{
   if (this.path.playing)
   {
      this.racer.move(1);
   }
}
EVR.Level.Delegate.prototype.sprint = function()
{
   this.path.sprint();
}
EVR.Level.Delegate.prototype.cancel_sprint = function()
{
   this.path.sprinting = false;
}
EVR.Level.Delegate.prototype.restart = function()
{
   var level = this.level;
   if (level.states[LEVEL_STATE_PAUSED] || level.states[LEVEL_STATE_FINISHED])
   {
      this.evr.load_level(level.id, level.practice);
   }
}
EVR.Level.Delegate.prototype.main_menu = function()
{
   var level = this.level;
   if (level.states[LEVEL_STATE_PAUSED] || level.states[LEVEL_STATE_FINISHED])
   {
      this.evr.unload_level();
   }
}
EVR.Level.Delegate.prototype.next_level = function()
{
   var level = this.level;
   if (level.states[LEVEL_STATE_FINISHED])
   {
      var id = parseInt(level.id);
      var evr = this.evr;
      if (level.next_level_is_available())
      {
	 evr.load_level(id + 1);
      }
      else if (id == LEVEL_LIMIT && level.is_clear())
      {
	 evr.load_ending();
      }
   }
}
EVR.Level.Delegate.prototype.toString = function()
{
   return "[object EVR.Level.Delegate]";
}
EVR.Level.Clock = function(level)
{
   EVR.Graphic.call(
      this, level.road, null, null, ALIGN_RIGHT, level.road.container);
   this.road = level.road;
   this.height = CLOCK_HEIGHT;
   this.build();
   this.append();
}
EVR.Level.Clock.prototype = new EVR.Graphic;
EVR.Level.Clock.prototype.build = function()
{
   this.set_proportions(CLOCK_WIDTH, this.height);
   this.set_opacity(CLOCK_OPACITY);
   this.set_color(CLOCK_BACKGROUND);
   this.set_text("00:00.000", CLOCK_FONT, CLOCK_TEXT_COLOR, CLOCK_TEXT_SIZE);
   this.css.fontWeight = CLOCK_FONT_WEIGHT;
   this.css.letterSpacing = CLOCK_LETTER_SPACING;
   this.set_line_height();
   this.css.overflow = "hidden";
   this.time = new EVR.Time();
}
EVR.Level.Clock.prototype.set_line_height = function()
{
   this.css.lineHeight = this.get_dimensions()[1] + "px";
}
EVR.Level.Clock.prototype.start = function()
{
   var current = this;
   this.timestamp = +new Date;
   this.interval = window.setInterval(
      function() {
	 current.measure();
      }, CLOCK_INTERVAL);
}
EVR.Level.Clock.prototype.measure = function()
{
   var timestamp = +new Date;
   var difference = timestamp - this.timestamp;
   this.time.add(difference);
   this.timestamp = timestamp;
   this.text.set(this.time.get_formatted());
}
EVR.Level.Clock.prototype.stop = function()
{
   if (!!this.interval)
   {
      window.clearInterval(this.interval);
      this.interval = null;
      this.measure();
   }
}
EVR.Level.Clock.prototype.toggle = function()
{
   if (!!!this.interval)
   {
      this.start();
   }
   else
   {
      this.stop();
   }
}
EVR.Level.Clock.prototype.place = function()
{
   EVR.Graphic.prototype.place.call(this);
   var y = this.road.borders.get_dimensions()[1];
   y += this.road.get_dimensions()[1];
   this.set_coordinates([null, y])
}
EVR.Level.Clock.prototype.draw = function()
{
   EVR.Graphic.prototype.draw.call(this);
   this.set_line_height();
}
EVR.Level.Clock.prototype.toString = function()
{
   return "[object EVR.Level.Clock]";
}
<?php
require_once "../account/get_user_path.php";
$GLOBALS["PROGRESS_FILE_NAME"] = "progress";
$path = account\get_user_path() . $GLOBALS["PROGRESS_FILE_NAME"];
$progress = trim(file_get_contents($path));
if (isset($_GET["clear"]) && $_GET["clear"] > $progress)
{
   $progress++;
   file_put_contents($path, $progress);
}
echo $progress;
<?php
require_once "../account/get_user_path.php";
$GLOBALS["FILE_NAME"] = "expert";
add_id_to_list();
function add_id_to_list()
{
   $id = $_GET["id"];
   $levels = get_list();
   if (!in_array($id, $levels))
   {
      $levels[] = $id;
   }
   file_put_contents(build_path(), implode(" ", $levels));
}
function get_list()
{
   $raw = file_get_contents(build_path());
   if ($raw == "")
   {
      return array();
   }
   return explode(" ", $raw);
}
function build_path()
{
   return account\get_user_path() . $GLOBALS["FILE_NAME"];
}
18.220.242.160
18.220.242.160
18.220.242.160
 
January 23, 2021

I wanted to document this chat-controlled robot I made for Babycastles' LOLCAM📸 that accepts a predefined set of commands like a character in an RPG party 〰 commands like walk, spin, bash, drill. It can also understand donut, worm, ring, wheels, and more. The signal for each command is transmitted as a 24-bit value over infrared using two Arduinos, one with an infrared LED, and the other with an infrared receiver. I built the transmitter circuit, and the receiver was built into the board that came with the mBot robot kit. The infrared library IRLib2 was used to transmit and receive the data as a 24-bit value.


fig. 1.1: the LEDs don't have much to do with this post!

I wanted to control the robot the way the infrared remote that came with the mBot controlled it, but the difference would be that since we would be getting input from the computer, it would be like having a remote with an unlimited amount of buttons. The way the remote works is each button press sends a 24-bit value to the robot over infrared. Inspired by Game Boy Advance registers and tracker commands, I started thinking that if we packed multiple parameters into the 24 bits, it would allow a custom move to be sent each time, so I wrote transmitter and receiver code to process commands that looked like this:

bit
name
description
00
time
multiply by 64 to get duration of command in ms
01
02
03
04
left
multiply by 16 to get left motor power
05
06
07
08
right
multiply by 16 to get right motor power
09
10
11
12
left sign
0 = left wheel backward, 1 = left wheel forward
13
right sign
0 = right wheel forward, 1 = right wheel backward
14
robot id
0 = send to player one, 1 = send to player two
15
flip
negate motor signs when repeating command
16
repeats
number of times to repeat command
17
18
19
delay
multiply by 128 to get time between repeats in ms
20
21
22
23
swap
swap the motor power values on repeat
fig 1.2: tightly stuffed bits

The first command I was able to send with this method that seemed interesting was one that made the mBot do a wheelie.

$ ./send_command.py 15 12 15 1 0 0 0 7 0 1
sending 0xff871fcf...


fig 1.3: sick wheels

A side effect of sending the signal this way is any button on any infrared remote will cause the robot to do something. The star command was actually reverse engineered from looking at the code a random remote button sent. For the robot's debut, it ended up with 15 preset commands (that number is in stonks 📈). I posted a highlights video on social media of how the chat controls turned out.

This idea was inspired by a remote frog tank LED project I made for Ribbit's Frog World which had a similar concept: press a button, and in a remote location where 🐸 and 🐠 live, an LED would turn on.


fig 2.1: saying hi to froggo remotely using an LED

😇 The transmitter and receiver Arduino programs are available to be copied and modified 😇