Ronit Banerjee, Oliver Terell

Slap-Jack, red-hands,  red tomato we all have played extremely childish games growing up that at times have involved slapping each other’s hands. The rules of this game are simple. One player places his hand on a table and the other tries to slap it. If the former manages to pull his hand away in time, he receives a point, otherwise the point goes to the latter. While this is an extremely simple game, there is significant non-verbal communication taking place between the two players.

We tries to recreate this game with an LED and a light-sensitive resistor to parallel this non-verbal communication. A dash of randomness is added to make the game more exciting. When the led turns on, the light sensitive resistor detects it and tries to turn it off by moving the servo down to the button. However at the same time, after a random delay, the first board tries to turn of the LED. If the button is pressed while the LED is on, then the second entity gains a point otherwise the first entity receives a point, an OLED screen driven by an i2c controller keeps track of the score. The LED then turns on again after a random delay.

I think one of the most interesting things of this project is that a human can interject himself into this conversation and press the button before any of the entities turn off the LED.

 

The solid works file and dxf file can be found here

Board 1 Code

</pre>
#include <Wire.h>
#include <Adafruit_SSD1306.h>
#include <Adafruit_GFX.h>

// OLED display TWI address
#define OLED_ADDR 0x3C

#define SWITCH 13
#define LED 8

#define LED_OFF_DELAY_LOWER 100
#define LED_OFF_DELAY_HIGHER 200

#define LED_RESET_DELAY_LOWER 3000
#define LED_RESET_DELAY_HIGHER 8000

Adafruit_SSD1306 display(-1);
int selfScore = 0;
int otherScore = 0;

void setup() {
  // initialize and clear display
  pinMode(SWITCH, INPUT);
  pinMode(LED, OUTPUT);

  display.begin(SSD1306_SWITCHCAPVCC, OLED_ADDR);
  display.clearDisplay();
  display.display();

  // display a line of text
  display.setTextSize(2);
  display.setTextColor(WHITE);
  display.setCursor(27,30);
  display.print("Hello, world!");

  // update display with all of the above graphics
  display.display();
}

void loop() {
  digitalWrite(LED, true);

  String message = "Bot 1: " + String(selfScore) + "\nBot 2: " + String(otherScore);

  display.clearDisplay();
  display.setCursor(0,0);
  display.print(message);
  display.display();

  int count = 0;
  bool selfWins = true;
  int randomTime = random(LED_OFF_DELAY_LOWER, LED_OFF_DELAY_HIGHER);

  while (count < randomTime)
  {
    count++;
    if (digitalRead(SWITCH))
    {
      otherScore++;
      selfWins = false;
      break;
    }
    delay(1);
  }
  digitalWrite(LED, false);

  if (selfWins)
  {
    selfScore++;
  }

  delay(random(LED_RESET_DELAY_LOWER, LED_RESET_DELAY_HIGHER));

}
<pre>

 

Board 2 Code

</pre>

#include <Servo.h>
Servo servo;
#define SERVO 3

#define PHOTORESISTOR 0
#define THRESHOLD 20

int val = 0;
int baseline;

void setup() {
  Serial.begin(9600);
  servo.attach(SERVO);
  servo.write(90);

  baseline = analogRead(PHOTORESISTOR);
}

void loop() {
  val = analogRead(PHOTORESISTOR);
  Serial.println(val);
  if (baseline - val > THRESHOLD) push_button();
  delay(20);
}

void push_button(){
  servo.write(180);
  delay(500);
  servo.write(90);
  delay(1000);
}

<pre>