120, rue Beacon, Somerville, MA 02143
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.

Temps estimé

Approximately 1 hour

Nombre de personnes

1 à 4 étudiants pour chaque main NeuroMaker disponible

Fournitures nécessaires

  • Une main NeuroMaker entièrement construite
  • Un ordinateur MacOS, Windows ou Chrome OS
  • Éditeur en ligne Arduino avec Arduino Create Agent entièrement installé

Fichiers de programme nécessaires

  • Veuillez consulter la répartition du code dans les instructions ci-dessous

Les préparatifs

  • Veuillez vous assurer que la main NeuroMaker dispose de piles fonctionnelles. Des voyants d'alimentation supplémentaires sur la carte d'alimentation de la main doivent s'allumer lorsque l'interrupteur marche/arrêt a été activé. Si vos doigts bougent de manière erratique ou ne bougent pas du tout après avoir téléchargé le code ci-dessous, cela peut signifier que vos piles sont faibles.
  • Veuillez vous assurer que l'agent de création Arduino et l'éditeur en ligne Arduino sont répertoriés en toute sécurité sur le pare-feu de votre district. Les instructions pour le personnel informatique sont fournies ici : Guide de référencement sécurisé de l'éditeur Arduino
  • Si vous n'avez pas encore installé l'éditeur Arduino, veuillez terminer le projet de configuration de l'environnement de codage C++

Arrière plan

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!

Instructions de projet

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);  
}

 

fr_FRFrench