Tinder Maths with XinaBox and the Raspberry Pi

Tinder Maths with XinaBox and the Raspberry Pi

Here is a quick demo of xChip OD01 - Display 128x64 (SSD1306) xChip SL06 - Gesture (APDS-9960). I call the demo "Tinder Maths". The program asks the user a maths problem. If the maths problem is correct, you swipe right, otherwise you swipe left. If you are familiar with the social media app called Tinder, you will get the gimmick.


  1. What you need
  2. To do
  3. Code
  4. Video guide


1. What you need


2. To do

  • Install the SL06 library:
pip install apds9960
  • Install the OD01 library:
Check out this Hackster Project. It shows how to install Richard Hull's OLED library.
  • Cut and paste the code below


3. Code

from apds9960.const import *
from apds9960 import APDS9960
import RPi.GPIO as GPIO
import smbus2 as smbus
from time import sleep
import random
from luma.core.virtual import terminal
import os
from PIL import ImageFont
from demo_opts import get_device

port = 1
bus = smbus.SMBus(port)

apds = APDS9960(bus)

dirs = {
    APDS9960_DIR_NONE: "none",
    APDS9960_DIR_LEFT: "left",
    APDS9960_DIR_RIGHT: "right",
    APDS9960_DIR_UP: "up",
    APDS9960_DIR_DOWN: "down",
    APDS9960_DIR_NEAR: "near",
    APDS9960_DIR_FAR: "far",

def make_font(name, size):
    font_path = os.path.abspath(os.path.join(
                    os.path.dirname(__file__), 'fonts', name))
    return ImageFont.truetype(font_path, size)

device = get_device()
term = terminal(device, make_font("miscfs_.ttf", 12))

def correct():
    global hs
    global term
    hs = hs + 1
    term.println ("CORRECT!")
    term.puts ("Streak Score: %d" % hs)

def incorrect():
    global hs
    global motion
    global term
    hs = 0
    term.puts("You swiped %s" % motion)

    tryagain = False
    hs = 0
    while True:
        if not tryagain:
            term.animate = False
            term.println("Tinder Math")
            term.animate = True
            right=random.choice([True, False])
            oper=random.choice(["-", "+"])
            a = random.randint(1, 10)
            b = random.randint(1, 10)
            if oper == "+":
                c = a+b
                c = a-b
            if not right:
                while r==0:
                c = c + r
            term.puts ("%d %s %d = %d " % (a,oper,b,c))
        while not apds.isGestureAvailable():
        tryagain = False
        motion = dirs.get(apds.readGesture(),"unknown")
        if right and motion=="right":
        elif not right and motion=="left":
        elif motion<>"left" and motion<>"right":
            tryagain = True

        term.println ("Bye")


4. Video guide


Please see our Raspberry Pi XK03 kit, which contains all the xChips needed to follow this project. The product page and online instructions contain useful links to getting started, sample code and projects.

Previous article Using Accelerometer to Determine Device Orientation - with the RasPi Kit
Next article Using Microsoft PowerShell and Raspberry Pi to Build a Weather Station with XinaBox