Next HW version

As always, times flies amazingly fast, and days quickly becomes weeks and even months. But even if the blog is rather silent a lot have happened in the background. The next hardware version is ready and I am currently working through each part to make sure it works as intended. So far I have found surprisingly few errors both on the schematic and the PCB layout. Actually, the number of errors found so far is zero which is a big surprise. Being an Engineer, it is very seldom something works the first time…

The new display, touch panel and even the vibration motor which I mentioned in the last post runs smoothly on the new hardware. I do have some issues with the sensitivity of the touch panel but it is most likely an error in my calibration routine and not hardware related.

Below is a video of a game I very quickly wrote to test the system. A circle randomly grows on the screen and you have a few seconds to hit it. If you do, you score one point and increases your hit-ratio. The game will also use the vibration motor to give haptic feedback when you successfully hit a circle.

A raw source code copy can be found below:

"Scene.init()\r\n"
"math.randomseed(System.millis())\r\n"
"local touch_valid_click = false\r\n"
"local touch_start_x = 0\r\n"
"local touch_start_x = 0\r\n"
"local speed = 50\r\n"
"local total_targets = 0\r\n"
"local total_hits = 0\r\n"
"local game_state = 0\r\n"
"local targets = {}\r\n"
"function targets.new_target(tx,ty)\r\n"
" return ( { x = tx,\r\n"
" y = ty,\r\n"
" active = 0,\r\n"
" speed = 0,\r\n"
" size = 0 })\r\n"
"end\r\n"
"function targets.make_pattern()\r\n"
" for , target in ipairs( targets ) do\r\n" " target.active=0\r\n" " end\r\n" " local r = math.random(9)\r\n" " targets[r].speed = speed\r\n" " targets[r].active = 1\r\n" " targets[r].size = 0\r\n" " total_targets = total_targets + 1\r\n" "end\r\n" "function targets.grow(delta)\r\n" " for , target in ipairs( targets ) do\r\n"
" if target.active == 1 then\n\r"
" target.size = target.size + target.speed*delta\r\n"
" if target.size > 32 then\r\n"
" target.size = 32\r\n"
" target.speed = -target.speed\r\n"
" end\r\n"
" if target.size < 0 then\r\n" " target.active = 0\r\n" " end\r\n" " end\r\n" " end\r\n" "end\r\n" "function targets.check_if_still_growing()\r\n" " for , target in ipairs( targets ) do\r\n" " if target.active == 1 then\r\n" " return true\r\n" " end\r\n" " end\r\n" " return false\n\r" "end\r\n" "table.insert(targets, targets.new_target(85,45))\r\n" "table.insert(targets, targets.new_target(85,120))\r\n" "table.insert(targets, targets.new_target(85,195))\r\n" "table.insert(targets, targets.new_target(160,45))\r\n" "table.insert(targets, targets.new_target(160,120))\r\n" "table.insert(targets, targets.new_target(160,195))\r\n" "table.insert(targets, targets.new_target(235,45))\r\n" "table.insert(targets, targets.new_target(235,120))\r\n" "table.insert(targets, targets.new_target(235,195))\r\n" "function targets.draw()\r\n" " for , target in ipairs( targets ) do\r\n" " if target.active == 1 then\r\n" " Graphics.draw_filled_circle(target.x, target.y, target.size)\r\n" " end\r\n" " end\r\n" "end\r\n" "function targets.check_for_hit(x,y)\r\n" " for _, target in ipairs( targets ) do\r\n" " if target.active == 1 then\r\n" " local dist = math.sqrt( (x - target.x) * (x - target.y) + (y - target.y) * (y - target.y))\r\n" " if dist < target.size + 40 or dist < 50 then\r\n" " target.active = 0\r\n" " total_hits = total_hits + 1\r\n" " Gamepad.play_haptic_effect(1)\r\n" " return true\r\n" " end\n\r" " end\r\n" " end\r\n" " return false\r\n" "end\r\n" "Scene.set_update_callback(function (delta)\r\n" " if game_state == 0 then\r\n" " targets.make_pattern()\r\n" " game_state = 1\r\n" " elseif game_state == 1 then\r\n" " targets.grow(delta)\r\n" " if not targets.check_if_still_growing() then\r\n" " game_state = 2\r\n" " end\r\n" " elseif game_state == 2 then\r\n" " game_state = 0\r\n" " end\n\r" "end)\r\n" "Scene.set_render_callback(function ()\r\n" " Graphics.set_color(Colors.White)\r\n" " Graphics.clear()\r\n" " Graphics.set_color(Colors.Black)\r\n" " targets.draw()\r\n" " Graphics.draw_text(4,4, \"Total:\")\r\n" " Graphics.draw_text(4,20, total_targets)\r\n" " Graphics.draw_text(4,36, \"Hits:\")\r\n" " Graphics.draw_text(4,52, total_hits)\r\n" " Graphics.draw_text(4,68, \"Ratio:\")\r\n" " local ratio = (total_hits*100)/total_targets\r\n" " Graphics.draw_text(4,84, string.format(\"%.0f %%\", ratio))\r\n" "end)\r\n" "Scene.set_touch_pressed_callback(function (x,y)\r\n" " touch_valid_click = true\r\n" " touch_start_x = x\r\n" " touch_start_y = y\r\n" " System.led(true)\r\n" "end)\n\r" "Scene.set_touch_moved_callback(function (x,y)\r\n" " local dist = math.sqrt( (x - touch_start_x ) * (x - touch_start_x ) + (y - touch_start_y) * (y - touch_start_y))\r\n" " if dist > 20 then touch_valid_click = false end\r\n"
" if touch_valid_click and targets.check_for_hit(x,y) then\n\r"
" touch_valid_click = false\r\n"
" end\r\n"
" System.led(touch_valid_click)\r\n"
"end)\n\r"
"Scene.set_touch_released_callback(function (x,y)\r\n"
" local dist = math.sqrt( (x - touch_start_x ) * (x - touch_start_x ) + (y - touch_start_y) * (y - touch_start_y))\r\n"
" if dist > 20 then touch_valid_click = false end\r\n"
" if touch_valid_click then\r\n"
" targets.check_for_hit(x,y)\r\n"
" end\r\n"
" touch_valid_click = false\r\n"
" System.led(false)\r\n"
"end)\r\n"