static int biteLED = 6; static int biteReciever = 7; static int openPosition = 90; static int closedPosition = 135; int biteTimer = -1; static int biteDelay = 250; void setup() { pinMode(biteLED, OUTPUT); } void loop() { int now = millis(); if(checkBite and biteTimer == -1) { biteTimer = closeMouth(); } if (now - biteTimer >= biteDelay) { // if biteDelay milliseconds have passed since the other function was called openMouth(); // this may need to be reworked to give better results biteTimer = -1; } } bool checkBite() { /* written by natalie * * checks if the dinosaur needs to bite * the threshold may need to be adjusted based on ambient light levels * */ static int threshold = 500; if (analogRead(biteReciever) < threshold) { return true; } return false; } int closeMouth() { /* written by natalie * * this closes the mouth to bite down and also starts a timer for when to stop biting * */ biteServo.write(closedPosition); return millis(); } void openMouth() { /* written by natalie * * this returns the mouth to its natural position * */ biteServo.write(openPosition); }