Stap 2: Making of
De uitleg van de code is volledig gemaakt binnen de code als commentaar. Welke twijfel hebt, voel je vrij om vragen.
#include <Wire.h> #include <Mesh.h> //This header is for the Aquila-only functions #include <AquilaProtocol.h> //This header is for the Aquila-only functions<br> #include <Servo.h> //Header needed for making use of the servo functions Servo a; //Here, we name the servo ‘a’, so we can call it. int pos = 0; bool isClosed = true; //This variable is for toggle function only. //This applies for the next 3 functions: //a.write(N) it says that when the function begins, the servo will move until position N (knowing that they can move from 0 to 180 degrees). //After this, it will wait (delay) for M miliseconds; 1000ms = 1 second. //After the delay, it will procced to write a new position to the servo, in this case is 9,for this is the grade where THIS servo in particular won’t force (this varies among servos, they don’t cover their entire 180 degrees; you’ll hear a buzz if you’re exceeding it’s limit). bool serve1(uint8_t param, bool gotParam) { a.write(80); delay(1000); a.write(9); } bool serve2(uint8_t param, bool gotParam) { a.write(50); delay(1000); a.write(9); } bool serve3(uint8_t param, bool gotParam) { a.write(40); delay(650); a.write(9); } //Toggle fuction is based on the previous functions. It "will wonder" if the servo is opened or closed. Knowing this, will proceed to close or open, accordingly. bool toggle(uint8_t param, bool gotParam) { if (isClosed) { isClosed = false; a.write(80); } else { isClosed = true; a.write(9); } } void setup() { a.attach(9); //Servo motor plugged to Altair's pin 9. a.write(9); //Servo stops vibrating/buzzing at 9º, so it's initial position is 9 being closed. (It's mere coincidence that the pin and degrees are the same). Mesh.begin(); Aquila.begin(); Aquila.setClass("mx.makerlab.test"); Aquila.setName("Feeder"); //Text among quotes is the one will appear on the hub as a button. //Right after the quoted text is que name of the fuction that will be called whenever the button on the hub is clicked. This is an Aquila-only function Aquila.addAction("Serve a lot", serve1); Aquila.addAction("Serve half", serve2); Aquila.addAction("Serve a little bit", serve3); Aquila.addAction("Toggle", toggle); Mesh.announce(HUB); //This line is needed in order for this Aquila appears on the hub } void loop() { Mesh.loop(); Aquila.loop(); }