Introduction
This is a simple BotSpine demo project. BotSpine already has a processor and display. A CR2032 battery will supply the power. The controllers to move the paddles up and down will simply be wires.
So, I'll have to solder a few wires to the BotSpine board, write a few lines of BASIC code, push the code to BotSpine over Bluetooth Low Energy (BLE) and that's it. Should be done in a couple of days. The hardest part will be finding a matchbox to prove that it fits. --- Well, at least that's the plan :).
Overview
Each game controller consists of 3 wires: a ground wire, wrapped around the player's finger and 2 other wires, taped to the table, which move the paddle up or down, when touched by the ground wire.
We could fire an interrupt whenever one of the control wires gets grounded. But, since we have to run a timed loop for the ball motion anyway, we might as well just check the state of the pins at each loop.
We will calculate the ball and paddle positions in a 1280 x 640 space and then display on the 128 x 64 pixel OLED display by dividing by 10.
Each new ball gets a random x and y velocity. When the ball gets to the top or bottom of the screen, the y velocity is reversed. When the ball gets to the side of the screen and passes by the paddle, the other player scores. Otherwise, the x velocity is reversed.
Code
The code will look something like this:
NEW 2 A=0 //left player score 3 S=0 //right player score 4 E=200 //ms Delay between loops 5 PINMODE P0(0) INPUT PULLUP // Player 0 (left) DOWN controller 6 PINMODE P0(1) INPUT PULLUP // Player 0 (left) UP controller 7 PINMODE P1(2) INPUT PULLUP // Player 1 (right) DOWN controller 8 PINMODE P1(3) INPUT PULLUP // Player 1 (right) UP controller 10 X=1280/2 //Ball X 20 Y=640/2 //Ball y 30 L=100 //paddle length 50 Q=640/2 //Left paddle center 60 W=640/2 //Right paddle center 80 T=40 //paddle speed 90 I=80 // top ball speed 95 P = 0 //loop counter index 110 U = I/2 - RND(I+1) // Ball speed in x direction 112 If ABS(U)<I/4 //Ball needs some x velocity 114 goto 110 116 END 120 O = I/2 - RND(I+1) // Ball speed in y direction 130 OLED CLEAR 140 OLED JUST C 145 OLED ROW 1 150 OLED FONT 2 1000 If P < L/10 1030 DRAWPIXEL 1,(Q-L/2)/10+P,1 //draw left paddle 1040 DRAWPIXEL 126,(W-L/2)/10+P,1 //draw right paddle 1050 P=P+1 1055 goto 1000 1060 End 1070 P=0 1080 DRAWPIXEL X/10,Y/10,1 //draw ball 1083 OLED A, " ",S //display score and render ball and paddles 1084 Delay E 1085 F = P0(1) 1086 G = P0(0) 1087 Q=Q+T*(G-F) //new paddle positions 1088 F = P1(2) 1089 G = P1(3) 1090 W=W+T*(G-F) //pins are internally pulled high. They read 1 unless grounded, then 0. 1100 If Q < L/2 //paddle running off screen 1110 Q=L/2 1120 END 1130 If Q > 630-L/2 1140 Q=630-L/2 1150 END 1160 If W < L/2 //running off screen 1170 W=L/2 1180 END 1190 If W > 630-L/2 1200 W=630-L/2 1210 END 1220 X=X+U 1230 Y=Y+O 1240 If Y < 1 // Ball bounces off Bottom 1250 O=0-O 1260 End 1270 If Y > 620 // Ball bounces off top 1280 O=0-O 1290 End 1300 If X < 1 1310 If Y > Q + L/2 //ball got past paddle 1320 S=S+1 //increment score 1330 Goto 10 //new ball 1340 END 1350 If Y < Q - L/2 1360 S=S+1 1370 Goto 10 //new ball 1380 END 1390 U=0-U //ball bounces off paddle 1400 END 1410 If X > 1260 1420 If Y > W + L/2 1430 A=A+1 1440 Goto 10 //new ball 1450 END 1460 If Y < W - L/2 1470 A=A+1 1480 Goto 10 //new ball 1490 END 1500 U=0-U //ball bounces off paddle 1510 END 1520 OLED CLEAR 1590 Goto 1000 //next loop