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.
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
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!
Instructions de projet
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); }