Plante Piranha (13 / 16 étapes)

Etape 13 : Le code

Pour tous ceux qui ne veulent pas télécharger le fichier ou veut juste de savoir ce qu’ils obtiennent avant qu’ils l’obtiennent, ici du code.

 /******************************************<br> PURPOSE: Piranha Plant Created by Aldo Reigosa DATE: 12/2014 *******************************************/ 
 #include // Library for the proximity sensor #include // Library for the servo #include // Library for the stepper motor 
 #define gearratio 64 // 1:64 gear ratio #define echoPin 5 // This is the echo pin #define triggerPin 6 // This is the trigger pin #define servopin 7 // This is the servo pin #define ledpin 12 // This is the LED pin 
 Servo myservo; // instantiate a Servo object named 'myservo' int x; // Integer used for 1st distance recorded int y; // Integer used for 2nd distance recorded volatile int z=0; // Integer used in the interrupt const int stepsPerRevolution = 2048; // Number of steps to complete a revolution Stepper myStepper(stepsPerRevolution,8,9,10,11); // Pins for the stepper motor 
 Piranha distanceSensor(echoPin,triggerPin); // The constructor to instantiate a sensor named "distanceSensor" 
 /***************************setup function*********************************/ 
 void setup() { Serial.begin(115200); // Start serial communication myservo.attach(servopin); // Attaches the servo on pin 7 to the servo object myStepper.setSpeed(0.8*gearratio); // Sets the speed for the stepper motor attachInterrupt(1,Interrupt,RISING); // Attaches the interrupt to pin 3 and activates when it is rising pinMode(ledpin, OUTPUT); // Sets the LED pin as an output pin } 
 /***************************main loop**********************************************/ 
 void loop() { float distance1 = distanceSensor.readSensor(); // Here we call the 'readSensor' method to determine the distance // and set it equal to distance1 if (distance1 > 0 && distance1 < 100){ // Here we set x=1 if the distance threshold is met x=1; // Otherwise x=0 } else { x=0; } Serial.print("distance1: "); // Prints the distance into the serial monitor. Serial.println(distance1); 
 delay(1000); // A 1 second delay 
 float distance2 = distanceSensor.readSensor(); // We take another distance measurement 
 if (distance2 > 0 && distance2 < 100 && x==1){ // If both the first and second distance are within the threshold myservo.write(180); // it will activate the servo to the 180 degree position and set y to 1 y=1; } else { // If either the first or second distance isn't within the threshold myservo.write(0); // the servo will return to the 0 position and set y to 0 y=0; } Serial.print("distance2: "); // Prints the distance into the serial monitor. Serial.println(distance2); 
 delay(1000); // Another 1 second delay 
 float distance3 = distanceSensor.readSensor(); // A final distance measurement labelled as distance3 
 if (distance3 > 0 && distance3 < 100 && x==1 && y==1 && z==1){ // If all three distances are within the threshold and the interrupt myStepper.step(stepsPerRevolution); // has been activated (thus removing the safety), it will activate delay(2000); // the stepper motor and delay for 2 seconds before resseting the x=0; // variables. Otherwise it will only delay for 1 second and start over. y=0; } else { delay(1000); } Serial.print("distance3: "); // Prints the distance into the serial monitor. Serial.println(distance3); 
 } void Interrupt(){ // This is the interrupt z=!z; // This will make the variable that change to the opposite value if (z==1){ // When z is equal to 1 it will turn on the LED pin to act as a digitalWrite(ledpin, HIGH); // cautionary warning light saying that it is ready to fire } else { digitalWrite(ledpin, LOW); } Serial.print(z); } 

Articles Liés

Comment crocheter une plante Piranha géant de Mario

Comment crocheter une plante Piranha géant de Mario

Dans ce tutoriel, vous apprendrez comment crocheter une version géante de la plante Piranha, pour la première fois dans les jeux Mario sur Super Nintendo. La plante remplie mesurera environ douze pouces de large et dix-neuf pouces de bouche à la tige
Plante Piranha mini

Plante Piranha mini

Bonjour à nouveau.Cette instructable a été créée par un manque général d'autres instructables Piranha Plant. La dernière fois que j'ai posté, j'ai fait une plante Piranha fonctionnelle qui pouvait tirer des plombs bb au peuple. Alors que c'était un p
Comment faire une plante Piranha avec un tube

Comment faire une plante Piranha avec un tube

pour cette plante, vous aurez besoinPerler beads :-Noir-Rouge-Blanc-Vert foncé-Vert clair* Papier à repasser* Fer* 2 grandes plaques* Un livre ou quelque chose de lourd et plat* Pinces * optionnel ** Un Tube vert (vous pouvez acheter ce wal mart pour
Piranha Plant - lit chat Super Mario

Piranha Plant - lit chat Super Mario

C'est mon 1er post Instructable nu avec moi.Voici le lit de chat j'ai fait conçu sur la plante Piranha de MarioÉtape 1: Choses vous aurez besoinmatériaux, que vous aurez besoin pour réaliser ce projet sont ;1) deux paniers de fleurs suspendus (j'ai u
BRICOLAGE de Piranha Plant

BRICOLAGE de Piranha Plant

Il s'agit d'un projet de bricolage simple pour faire votre propre plante Piranha.Le « canal » est imprimé avec une imprimante 3D.Il s'agit d'un projet très simple et rapide à faire !Étape 1: conception J'ai fait la Pipe avec Tinkercad.Il suffit de fi
Piranha Plant porte-crayons

Piranha Plant porte-crayons

Presque chacun d'entre nous ont joué Super Mario Bros. J'ai avait recueilli quelques rouleaux de papier hygiénique pour un autre projet et cherchait à eux et il m'a frappé, je peux faire un porte-crayon. Mais de quoi ? DUH ! Plante Piranha ! Cela cer
(Mario Bros) Piranha Plant Cupcake

(Mario Bros) Piranha Plant Cupcake

présentant la plante Piranha, (à partir de Mario Brothers), Cupcake !  Si vous faites cela, je suggère que vous faites seulement une et pour l'anniversaire enfant/adulte.  Parce qu'elles prennent beaucoup de temps et beaucoup de baby-sitting.  Oh, et
Mario Brothers Piranha Plant boucles d’oreilles !

Mario Brothers Piranha Plant boucles d’oreilles !

Piranha Plant boucles d'oreilles !J'adore Mario Brothers.Et je l'adore geek inspiré de l'artisanat.Ces boucles d'oreilles Piranha Plant sont mes préférés à ce jour !Étape 1: fournitures Let's make a certains.Vous aurez besoin :Argile polymère rouge,
Super Mario Piranha plante lampe de lampe IKEA $10

Super Mario Piranha plante lampe de lampe IKEA $10

Bonjour à tous, c'est le genre de suite à ma lampe IKEA R2D2 instructable.Eh bien, mon plus vieux garçon veut changer sa chambre de Star Wars pour Super Mario pour un thème.  Qui est bon, parce que celui plus jeune veut une chambre de Star Wars, qui
Mario 3D imprimable Sewer Pipe & Piranha plante

Mario 3D imprimable Sewer Pipe & Piranha plante

il s'agit d'une courbe d'apprentissage pour moi. J'ai utilisé des applications de dessin mais j'ai jamais essayé de créer quelque chose dans un environnement 3D. Donc suivre avec moi pendant que j'essaye de créer un Super Mario Pipe pour un planteur
Super Mario Piranha Plant Cookie Cupcakes

Super Mario Piranha Plant Cookie Cupcakes

petits gâteaux au chocolat avec un biscuit de sucre glace royal haut et dents de maïs de bonbons.Les plantes Piranha sont les grandes plantes carnivores rencontrées tout au long de la série Mario. Voici comment transformer ces plantes en un régal que
Mario Party 10 Birthday Party Plan

Mario Party 10 Birthday Party Plan

Fête d'anniversaire un autre plan de MimicNecho ! Notre dernier était un thème Digimon pour les 8e anniversaire de Zander. Vous pouvez vérifier qu'ici :Celui-ci était le choix de Kaiden pour son 5ème anniversaire. Mario Party a toujours été un favori
Pièces maîtresses de 8 bits

Pièces maîtresses de 8 bits

faire votre propre pièce maîtresse la 8bits génial pour votre prochain dîner d'inspiration jeu vidéo ou un événement. C' est simple, nécessite très peu de talents artistiquesou outils et les magasins plat pour une utilisation ultérieure ! Vous rencon
3D Super Mario Papercraft Magnet Conseil

3D Super Mario Papercraft Magnet Conseil

Cubeecraft a un choix impressionnant de papercraft jouets en utilisant une conception astucieuse boîte non-colle. Le fan de la culture pop art couvre les personnages de TV, dessins animés, jeux vidéo, films, bandes dessinées et plus. Nous vous montro