I recreated the motion of two things high fiving each other!
My circuit:
Servo placed in toothpaste/tabasco box housing to move arm:
Toothpaste/tabasco box taped to cardboard strip
Used tape, boxcutter, and cardboard strip to make hands
Speakers were also attached to play music when the high five was executed successfully.
Code:
#include <Servo.h> #include "pitches.h" boolean previous = LOW; Servo myServoLeft; Servo myServoRight; // notes in the melody: int melody[] = { NOTE_C4, NOTE_G3, NOTE_E2, NOTE_A3, NOTE_G3, 0, NOTE_B3, NOTE_C4 }; // note durations: 4 = quarter note, 8 = eighth note, etc.: int noteDurations[] = { 4, 8, 8, 4, 4, 4, 4, 4 }; void setup() { // put your setup code here, to run once: pinMode(6, INPUT); myServoLeft.attach(10); myServoLeft.write(0); myServoRight.attach(11); myServoRight.write(45); Serial.begin(9600); } void loop() { // put your main code here, to run repeatedly: myServoLeft.write(30); myServoRight.write(30); if (digitalRead(6) == HIGH and previous == LOW) { myServoLeft.write(90); myServoRight.write(90); //tone(8, melody[NOTE_C4], 50); delay(500); myServoLeft.write(30); myServoRight.write(30); //tone(8, melody[random(0,7)], 100); delay(500); //firstTime = false; tone(8, melody[0], 100); delay(200); tone(8, melody[3], 100); delay(200); tone(8, melody[2], 100); delay(200); tone(8, melody[0], 100); delay(500); } previous = digitalRead(6); }