Makerming
Published © MIT

Face Hitting Machine With Sound Effect - Based on Arduino

A Face Hitting Machine enables you hit those you dislike on the face, even with uplifting slap sound effect. Your decompression artifact.

IntermediateFull instructions provided10 hours1,271

Things used in this project

Hardware components

Seeeduino V4.2
Seeeduino V4.2
×1
Base Shield V2
Seeed Base Shield V2
×1
Grove - MP3 v2.0
Seeed Grove - MP3 v2.0
×1
Seeed Motor Speed Sensor Module
×1
Seeed Grove - Gesture(PAJ7620U2)
×1
Seeed Grove - Servo
×1
Seeed Grove - Universal 4 Pin Buckled Cable
×3
Loudspeaker
×1
SD Card/ TF Card
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Laser cutter (generic)
Laser cutter (generic)
Printer
Hot melt glue gun

Story

Read more

Custom parts and enclosures

HitOnTheFace - MakerMing

pia_Ud3fy7tUmO.mp3

Code

HitOnTheFace - MakerMing.ino

C/C++
/*
 * TM1637.cpp
 * A library for the 4 digit display
 *
 * Copyright (c) 2012 seeed technology inc.
 * Website    : www.seeed.cc
 * Author     : Frankie.Chu
 * Create Time: 9 April,2012
 * Change Log :
 *
 * The MIT License (MIT)
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

#include "TM1637.h"
#include "Servo.h"
#include <Wire.h>
#include "paj7620.h"
#include "KT403A_Player.h"


const int CLK = 7;
const int DIO = 8;
TM1637 tm1637(CLK,DIO);

int leftplaytime = 50;
 
Servo myservo; 

#define GES_REACTION_TIME    5      // You can adjust the reaction time according to the actual circumstance.
#define GES_ENTRY_TIME      10     // When you want to recognize the Forward/Backward gestures, your gestures' reaction time must less than GES_ENTRY_TIME(0.8s). 
#define GES_QUIT_TIME   15


#ifdef __AVR__
#include <SoftwareSerial.h>
SoftwareSerial SSerial(2, 3); // RX, TX
#define COMSerial SSerial
#define ShowSerial Serial 

KT403A<SoftwareSerial> Mp3Player;
#endif

#ifdef ARDUINO_SAMD_VARIANT_COMPLIANCE
#define COMSerial Serial1
#define ShowSerial SerialUSB 

KT403A<Uart> Mp3Player;
#endif

#ifdef ARDUINO_ARCH_STM32F4
#define COMSerial Serial
#define ShowSerial SerialUSB 

KT403A<HardwareSerial> Mp3Player;
#endif

static uint8_t recv_cmd[8] = {};


void setup()
{

  pinMode(3, INPUT_PULLUP);   //configure digital pin2 as an input and enable the internal pull-up resistor
  pinMode(13, OUTPUT);
  
  tm1637.init();
  tm1637.set(BRIGHT_TYPICAL);//BRIGHT_TYPICAL = 2,BRIGHT_DARKEST = 0,BRIGHTEST = 7;
  tm1637.displayNum(leftplaytime);  

  myservo.attach(6);
  myservo.write(45);


uint8_t error = 0;
  Serial.begin(115200);   //start serial connection
  
  error = paj7620Init();      // initialize Paj7620 registers
    tm1637.displayNum(leftplaytime);  
    
  if (error) 
  {
    Serial.print("INIT ERROR,CODE:");
    Serial.println(error);
  }
  else
  {
    Serial.println("INIT OK");
  }
  Serial.println("Please input your gestures:\n");


  // put your setup code here, to run once:
 
    ShowSerial.begin(9600);
    COMSerial.begin(9600);
    while (!ShowSerial);
    while (!COMSerial);
    Mp3Player.init(COMSerial);


}

void loop()
{
  int sensorVal = digitalRead(3);  //read the speed sensor value into a variable  

  tm1637.displayNum(leftplaytime);  

 
  //put coins to increase leftplaytime, one coin for 5 times;

  if (sensorVal == 1) {
    digitalWrite(13, LOW);
    leftplaytime = leftplaytime+5;
    tm1637.displayNum(leftplaytime);  
    delay (300);
 } 
 else {
    digitalWrite(13, HIGH);
    tm1637.displayNum(leftplaytime);  
    }

  uint8_t data = 0, data1 = 0, error;
  
  error = paj7620ReadReg(0x43, 1, &data);       // Read Bank_0_Reg_0x43/0x44 for gesture result.
  if (!error) 
  {
    switch (data)                   // When different gestures be detected, the variable 'data' will be set to different values by paj7620ReadReg(0x43, 1, &data).
    {
      case GES_RIGHT_FLAG:
        delay(GES_ENTRY_TIME);
        paj7620ReadReg(0x43, 1, &data);
        if(data == GES_FORWARD_FLAG) 
        {
          Serial.println("Forward");
          delay(GES_QUIT_TIME);
        }
        else if(data == GES_BACKWARD_FLAG) 
        {
          Serial.println("Backward");
          delay(GES_QUIT_TIME);
        }
        else if (leftplaytime > 0)
        {
      Serial.println("Right");
          myservo.write(90);
          leftplaytime=leftplaytime-1;
           Mp3Player.play();
          delay (5);
        }          
                else{
            tm1637.displayNum(0);  }
        break;
        
      case GES_LEFT_FLAG: 
        delay(GES_ENTRY_TIME);
        paj7620ReadReg(0x43, 1, &data);
        if(data == GES_FORWARD_FLAG) 
        {
          Serial.println("Forward");
          delay(GES_QUIT_TIME);
        }
        else if(data == GES_BACKWARD_FLAG) 
        {
          Serial.println("Backward");
          delay(GES_QUIT_TIME);
        }
        else if(leftplaytime > 0)
        {
       Serial.println("Left");
          myservo.write(0);
          leftplaytime=leftplaytime-1;
           Mp3Player.play();
          delay (5);
        }          
        else{
            tm1637.displayNum(0);  }
        break;

          case GES_UP_FLAG:
        delay(GES_ENTRY_TIME);
        paj7620ReadReg(0x43, 1, &data);
        if(data == GES_FORWARD_FLAG) 
        {
          Serial.println("Forward");
          delay(GES_QUIT_TIME);
        }
        else if(data == GES_BACKWARD_FLAG) 
        {
          Serial.println("Backward");
          delay(GES_QUIT_TIME);
        }
        else
        {
          Serial.println("Up");
           myservo.write(45);
          delay (5);
        }          
        break;
      
    }
  }
  delay(10);
  
}

SlapTheTrump.ino

C/C++
/*
 * TM1637.cpp
 * A library for the 4 digit display
 *
 * Copyright (c) 2012 seeed technology inc.
 * Website    : www.seeed.cc
 * Author     : Frankie.Chu
 * Create Time: 9 April,2012
 * Change Log :
 *
 * The MIT License (MIT)
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

#include "TM1637.h"
#include "Servo.h"
#include <Wire.h>
#include "paj7620.h"
#include "KT403A_Player.h"


const int CLK = 7;
const int DIO = 8;
TM1637 tm1637(CLK,DIO);

int leftplaytime = 50;
 
Servo myservo; 

#define GES_REACTION_TIME    5      // You can adjust the reaction time according to the actual circumstance.
#define GES_ENTRY_TIME      10     // When you want to recognize the Forward/Backward gestures, your gestures' reaction time must less than GES_ENTRY_TIME(0.8s). 
#define GES_QUIT_TIME   15


#ifdef __AVR__
#include <SoftwareSerial.h>
SoftwareSerial SSerial(2, 3); // RX, TX
#define COMSerial SSerial
#define ShowSerial Serial 

KT403A<SoftwareSerial> Mp3Player;
#endif

#ifdef ARDUINO_SAMD_VARIANT_COMPLIANCE
#define COMSerial Serial1
#define ShowSerial SerialUSB 

KT403A<Uart> Mp3Player;
#endif

#ifdef ARDUINO_ARCH_STM32F4
#define COMSerial Serial
#define ShowSerial SerialUSB 

KT403A<HardwareSerial> Mp3Player;
#endif

static uint8_t recv_cmd[8] = {};


void setup()
{

  pinMode(2, INPUT_PULLUP);   //configure digital pin2 as an input and enable the internal pull-up resistor
  pinMode(13, OUTPUT);
  
  tm1637.init();
  tm1637.set(BRIGHT_TYPICAL);//BRIGHT_TYPICAL = 2,BRIGHT_DARKEST = 0,BRIGHTEST = 7;
  tm1637.displayNum(leftplaytime);  

  myservo.attach(6);
  myservo.write(45);


uint8_t error = 0;
  Serial.begin(115200);   //start serial connection
  
  error = paj7620Init();      // initialize Paj7620 registers
    tm1637.displayNum(leftplaytime);  
    
  if (error) 
  {
    Serial.print("INIT ERROR,CODE:");
    Serial.println(error);
  }
  else
  {
    Serial.println("INIT OK");
  }
  Serial.println("Please input your gestures:\n");


  // put your setup code here, to run once:
 
    ShowSerial.begin(9600);
    COMSerial.begin(9600);
    while (!ShowSerial);
    while (!COMSerial);
    Mp3Player.init(COMSerial);


}

void loop()
{
  int sensorVal = digitalRead(3);  //read the speed sensor value into a variable  

  tm1637.displayNum(leftplaytime);  

 
  //put coins to increase leftplaytime, one coin for 5 times;

  if (sensorVal == 1) {
    digitalWrite(13, LOW);
    leftplaytime = leftplaytime+5;
    tm1637.displayNum(leftplaytime);  
    delay (300);
 } 
 else {
    digitalWrite(13, HIGH);
    tm1637.displayNum(leftplaytime);  
    }

  uint8_t data = 0, data1 = 0, error;
  
  error = paj7620ReadReg(0x43, 1, &data);       // Read Bank_0_Reg_0x43/0x44 for gesture result.
  if (!error) 
  {
    switch (data)                   // When different gestures be detected, the variable 'data' will be set to different values by paj7620ReadReg(0x43, 1, &data).
    {
      case GES_RIGHT_FLAG:
        delay(GES_ENTRY_TIME);
        paj7620ReadReg(0x43, 1, &data);
        if(data == GES_FORWARD_FLAG) 
        {
          Serial.println("Forward");
          delay(GES_QUIT_TIME);
        }
        else if(data == GES_BACKWARD_FLAG) 
        {
          Serial.println("Backward");
          delay(GES_QUIT_TIME);
        }
        else if (leftplaytime > 0)
        {
      Serial.println("Right");
          myservo.write(90);
          leftplaytime=leftplaytime-1;
           Mp3Player.play();
          delay (5);
        }          
                else{
            tm1637.displayNum(0);  }
        break;
        
      case GES_LEFT_FLAG: 
        delay(GES_ENTRY_TIME);
        paj7620ReadReg(0x43, 1, &data);
        if(data == GES_FORWARD_FLAG) 
        {
          Serial.println("Forward");
          delay(GES_QUIT_TIME);
        }
        else if(data == GES_BACKWARD_FLAG) 
        {
          Serial.println("Backward");
          delay(GES_QUIT_TIME);
        }
        else if(leftplaytime > 0)
        {
       Serial.println("Left");
          myservo.write(0);
          leftplaytime=leftplaytime-1;
           Mp3Player.play();
          delay (5);
        }          
        else{
            tm1637.displayNum(0);  }
        break;

          case GES_UP_FLAG:
        delay(GES_ENTRY_TIME);
        paj7620ReadReg(0x43, 1, &data);
        if(data == GES_FORWARD_FLAG) 
        {
          Serial.println("Forward");
          delay(GES_QUIT_TIME);
        }
        else if(data == GES_BACKWARD_FLAG) 
        {
          Serial.println("Backward");
          delay(GES_QUIT_TIME);
        }
        else
        {
          Serial.println("Up");
           myservo.write(45);
          delay (5);
        }          
        break;
      
    }
  }
  delay(10);
  
}

Credits

Makerming

Makerming

2 projects • 1 follower

Comments

Add projectSign up / Login