Piranha Plant (13 / 16 stap)

Stap 13: De code

Voor wie niet wilt downloaden van het bestand of wil gewoon om te weten wat krijgen ze voordat ze het, hier is de 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); } 

Gerelateerde Artikelen

Piranha Plant - Super Mario kat bed

Piranha Plant - Super Mario kat bed

Dit is mijn 1e Instructable post dus kale met mij.Hier is de kat bed ik gemaakt ontworpen op de Piranha Plant uit MarioStap 1: Dingen die je zal nodigmaterialen die u nodig hebben zal om dit project te voltooien zijn;1) twee hangbakken bloem (ik gebr
Piranha Plant potlood houder

Piranha Plant potlood houder

Bijna alle van ons hebben gespeeld Super Mario Bros. Ik had verzameld sommige rollen wc-papier voor een ander project en was op zoek naar hen kan en het raakte me, ik een potlood houder. Maar van wat? DUH! Piranha Plant! Dit zeker bleek een veel bete
Hoe haak een gigantische Mario Piranha Plant

Hoe haak een gigantische Mario Piranha Plant

In deze tutorial leert u hoe een gigantische versie van de Piranha Plant, voor het eerst gezien in de Mario games voor de Super Nintendo haak. De voltooide plant meet ongeveer twaalf inch en negentien inch uit mond te stoppen.Voor deze tutorial, ik g
(Mario Bros) Piranha Plant Cupcake

(Mario Bros) Piranha Plant Cupcake

invoering van de Piranha Plant, (uit Mario Brothers), Cupcake!  Als u dit doet, ik stel voor dat u slechts één, en voor de verjaardag kind/volwassene.  Omdat dit een lange tijd en een heleboel babysit halen.  Oh, en... Misschien wilt u niet te maken
DIY Piranha Plant

DIY Piranha Plant

Dit is een eenvoudige DIY-project voor het maken van uw eigen Piranha Plant.De "pijp" wordt met 3D-printer afgedrukt.Dit is een echt eenvoudig en snel project te doen!Stap 1: Design Ik maakte de pijp met Tinkercad.Net hechten een buis op een gro
Hoe maak je een Piranha plant met een buis

Hoe maak je een Piranha plant met een buis

voor deze Plant zult u moetenPerler kralen:-Zwart-Rood-Wit-Donkergroen-Helder groen* Strijken papier* Ijzer* 2 grote Afdruiprekken* Een boek of iets zwaar en plat* Pincet * optionele ** Een groene buis (u kunt dit kopen bij wal-mart voor 2,00 dollar
Mario Brothers Piranha Plant oorbellen!

Mario Brothers Piranha Plant oorbellen!

Piranha Plant oorbellen!Ik houd absoluut van Mario Brothers.En I absolutely love geek geïnspireerd ambachten.Deze oorbellen Piranha Plant zijn mijn favoriet tot nu toe!Stap 1: benodigdheden Laten we enkele.U moet:ROOD, groen en wit polymeerklei1 tand
Super Mario Piranha Plant Lamp van 10 dollar IKEA Lamp

Super Mario Piranha Plant Lamp van 10 dollar IKEA Lamp

Hallo allemaal, dit is een soort van een follow-up van mijn IKEA R2D2 lamp instructable.Nou, wil mijn oudste jongen omzetten in zijn kamer uit Star Wars Super Mario voor een thema.  Dat is goed omdat de jongere een wil een Star Wars-kamer, wat beteke
Mini Piranha Plant

Mini Piranha Plant

Hallo weer.Dit instructable is ontstaan uit een algemeen gebrek aan andere Piranha Plant instructables. Laatste keer dat ik heb gepost, maakte ik een functionele Piranha Plant dat kan brand bb pellets op mensen. Terwijl dat een cool project was, het
3D afdrukbare Mario riool pijp & Piranha Plant

3D afdrukbare Mario riool pijp & Piranha Plant

dit is een leerproces voor mij. Ik heb gebruikt tekening apps maar ik heb nooit geprobeerd het creëren van iets in een 3D omgeving. Dus volg samen met mij als ik probeer te maken van een Super Mario Pipe voor een planter en een beruchte Piranha Plant
LED Super Mario Piranha Plant

LED Super Mario Piranha Plant

We zijn gaan maken van een Arduino controle LED Piranha Plant:]Stap 1: Benodigdheden Arduino Uno9 resisters9 LEDs - rood, geel, oranje is het beste, omdat zij moeten minder stroomsterktePIR-sensor9V batterijArduino stekker (u zult het snijden van de
Super Mario Piranha Plant Cookie Cupcakes

Super Mario Piranha Plant Cookie Cupcakes

chocolade cupcakes met een Koninklijk Suikerglazuur suiker cookie top en candy corn tanden.De Piranha planten zijn de grote, vleesetende planten ondervonden gedurende de Mario-serie. Hier is hoe om te zetten van deze planten in een traktatie die kunt
Piranha Planter

Piranha Planter

A Mario Bros thema planter.  Het enige plantje kon houden, maar ten behoeve van awesomeness, heb ik gekozen om het te vullen met venus fly vallen. Gemaakt van goedkoop en gemakkelijk beschikbare materialen, zou dit een perfect weekend project soop-up
Koopa Troopa Bacon schildpad hamburgers

Koopa Troopa Bacon schildpad hamburgers

U een niet-zo-geheime nostalgie haven voor Super Mario Brothers? Een diepe, vettige Liefde voor spek? Houd je horloge voor verborgen munten en paddo? Vervolgens bewijzen uw side-scrolling street cred door het nemen van een volledige leger van Koopa T