120 Beacon St, Somerville, MA 02143
Create a Program that Displays a Gesture

Welcome to programming the NeuroMaker Hand using C++ programming! In this project, we are going to build a custom function that will be able to display a gesture we want to make ourselves.

 

Estimated Time

Approximately 1 hour

Number of People

1-4 students for each available NeuroMaker Hand

Necessary Supplies

  • One fully built NeuroMaker Hand
  • One MacOS, Windows or Chrome OS computer
  • Arduino Online Editor with Arduino Create Agent fully installed

Necessary Program Files

  • Please see the code breakdown in the below instructions

Preparations

  • Please ensure that the NeuroMaker Hand has working batteries. Additional power lights on the power board of the Hand should turn on when the on/off switch has been turn on. If your fingers move erratically or don’t move it all after uploading the below code this could mean that your batteries are running low.
  • Please ensure that the Arduino Create Agent and Arduino Online Editor are safe listed on your district firewall. Instructions for IT personnel is provided here: IP Addresses Safelist Guide
  • In case you have not yet installed the Arduino Editor, please complete the Set Up C++ Coding Environment Project

Background

If you ever need to make a rock gesture, scissors gesture, pinch grip, crush grip or other movement with your hands, you will notice that you will need multiple different fingers moving to a certain position. When programming each individual motor to move a certain way, you might quickly find that listing out the same individual finger movements over and over again can become quite tedious. Thankfully we have functions! In this project, we will build out specific functions using C++ to create a rock, paper and scissors gesture. We will also be able to use a random number to generate these gestures and play rock, paper, scissors with our NeuroMaker Hand!

Project Instructions

Please follow the instructions in the following presentation walkthrough!

Create a Program that Displays a Gesture Walkthrough

For your convenience, the code in this project has been provided below

/*
This  program lets the hand play rock paper scissors and shows a random gesture every 3 seconds.
*/

//include the servo library to control the servo motors
#include <Servo.h>

//create 5 servos in an array
Servo servos[5];

//set up servo motors of fingers//set up servo motors of fingers

void setup() {
  //servos 0, 1, 2, 3, and 4 move the thumb, index, middle, ring, and pinkie fingers respectively.
  servos[0].attach(6);
  servos[1].attach(5);
  servos[2].attach(4);
  servos[3].attach(3);
  servos[4].attach(2);
  
  //start with rock position (fist) and wait 3 sec
  rock();
  delay(3000);
}


void rock() {
  //servos close all the fingers to a fist/rock
  servos[0].write(180);
  servos[1].write(0);
  servos[2].write(180);
  servos[3].write(180);
  servos[4].write(0);
  return;
}

void paper() {
  //fingers open up to form the paper gesture
  servos[0].write(0);
  servos[1].write(180);
  servos[2].write(0);
  servos[3].write(0);
  servos[4].write(180);
  return;
}

void scissors() {
  //the index and middle fingers are up in the scissors gesture
  servos[0].write(180);
  servos[1].write(180);
  servos[2].write(0);
  servos[3].write(180);
  servos[4].write(0);
  return;
}

void loop() {
  //create a random number of either 0, 1, or 2
  long randNum = random(3);
  
  //show a gesture based on the random number
  if (randNum==0){
    rock();
  }
  else{
    if (randNum==1){
      paper();
    }
    else{
      rock();
    }
  }
  
  //wait 3 seconds
  delay(3000);  
}

 

en_USEnglish