Stap 3: Arduino Sketch
Eigenlijk, zoals hieronder de code is ongecompliceerd. We altijd de waarde van de ultrasone sensor controleert en wanneer het wordt minder dan 40 cm, wij onze AC Lamp 3 keer als indicatie voor het vastleggen, zal knipperen, dan zal de camera de opname en ten slotte de mobiele het beeld zal post op twitter. Slechts een regel code voor het vastleggen en een andere voor tweeting.
/* Include 1Sheeld library. */ #include <OneSheeld.h>const int trigPin = 2; const int echoPin = 4; const int ledPin = 13;void setup() { /* Start communication. */ OneSheeld.begin(); pinMode(ledPin, OUTPUT); pinMode(trigPin, OUTPUT); pinMode(echoPin, INPUT); }void loop() { long duration, cm; digitalWrite(trigPin, LOW); delayMicroseconds(2); digitalWrite(trigPin, HIGH); delayMicroseconds(10); digitalWrite(trigPin, LOW); duration = pulseIn(echoPin, HIGH); // convert the time into a distance cm = microsecondsToCentimeters(duration); if(cm <= 40){ digitalWrite(ledPin, HIGH); // turn the LED on (HIGH is the voltage level) delay(1000); // wait for a second digitalWrite(ledPin, LOW); // turn the LED off by making the voltage LOW delay(1000); digitalWrite(ledPin, HIGH); // turn the LED on (HIGH is the voltage level) delay(1000); digitalWrite(ledPin, LOW); // turn the LED off by making the voltage LOW delay(1000); digitalWrite(ledPin, HIGH); // turn the LED on (HIGH is the voltage level) delay(1000); // wait for a second digitalWrite(ledPin, LOW); // turn the LED off by making the voltage LOW delay(1000); Camera.setFlash(ON); /* Take the picture. */ Camera.rearCapture(); /* Wait for 10 seconds. */ delay(10000); /* Post the picture on Twitter. */ Twitter.tweetLastPicture("We are having fun at Cairo mini #makerfaire, photo taken by and }delay(100); }long microsecondsToCentimeters(long microseconds) { return microseconds / 29 / 2; }