Display a Random Number on the NeuroMaker Hand
Welcome to programming the NeuroMaker Hand using C++ programming! In this project, we are going to build different functions that allow us to present different random number gestures using the NeuroMaker Hand.
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: Arduino Editor Safe listing Guide
- In case you have not yet installed the Arduino Editor, please complete the Set Up C++ Coding Environment Project
Background
With the five digits on our hand, we can conduct simple number communication. Hold up a pointer finger and we can non-verbally present a number one. Hold up two fingers a two, three fingers a three, etc. This sound easy enough with our new programming skills. However just like building custom functions, writing out a series of if statements or hard to follow logic can also get tedious. Thankfully we can now introduce switch case statements! Following the instructions below you will see how you can introduce a series of situations that you can call on command instead of filling your programming screen with tons of if statements. Let’s take a look!
Project Instructions
Please follow the instructions in the following presentation walkthrough!
Display a Random Number on the NeuroMaker Hand Walkthrough
For your convenience, the code in this project has been provided below
/* This program causes the hand to display a random number from 0 to 5. */ //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 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 zero(); delay(3000); } void zero() { //servos close all the fingers to a fist servos[0].write(180); servos[1].write(0); servos[2].write(180); servos[3].write(180); servos[4].write(0); return; } void one() { //the index finger is up servos[0].write(180); servos[1].write(180); servos[2].write(180); servos[3].write(180); servos[4].write(0); return; } void two() { //the index and middle fingers are up, forming a two servos[0].write(180); servos[1].write(180); servos[2].write(0); servos[3].write(180); servos[4].write(0); return; } void three() { //the index, middle, and ring fingers are up, forming a three servos[0].write(180); servos[1].write(180); servos[2].write(0); servos[3].write(0); servos[4].write(0); return; } void four() { //the index, middle, ring, and pinkie fingers are up, forming a four servos[0].write(180); servos[1].write(180); servos[2].write(0); servos[3].write(0); servos[4].write(180); return; } void five() { //all fingers are up, forming a five servos[0].write(0); servos[1].write(180); servos[2].write(0); servos[3].write(0); servos[4].write(180); return; } void loop() { //create a random number of either 0, 1, 2, 3, 4, or 5 long randNum = random(6); //show a gesture based on the random number switch(randNum){ case 0: zero(); break; case 1: one(); break; case 2: two(); break; case 3: three(); break; case 4: four(); break; case 5: five(); break; } //wait 3 seconds delay(3000); }