Hackster is hosting Hackster Holidays, Finale: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Tuesday!Stream Hackster Holidays, Finale on Tuesday!
Joyce LiuJaclyn BerrySahana RajasekarMaxwell N Rutman
Published

yūrn

A locked jar that addresses overeating and impulse control through auditory, tactile, and social feedback.

Full instructions provided1,051
yūrn

Story

Read more

Code

test_photo_servo.ino

C/C++
test_photo_servo.ino
#include <Servo.h>

Servo servo1;
int val;
boolean recentlyOpened;

void setup()
{
servo1.attach(9);
recentlyOpened = true;
}
void loop()
{
  val = analogRead(0);  
  int position;
  servo1.write(0);  
 
  if(val <= 500 && recentlyOpened == true){
    recentlyOpened=false;
    for(position = 180; position >= 0; position -= 20)
    {
      servo1.write(position);
      delay(500); 
    }
  } 
  
  if (val>=800){
    recentlyOpened = true; 
  }
} 

sound_test1.ino

Plain text
sound_test1.ino
#include <Wtv020sd16p.h>

/*
 Example: Control a WTV020-SD-16P module to play voices from an Arduino board
 */

#include <Wtv020sd16p.h>

int val;
int resetPin = 2;  // The pin number of the reset pin.
int clockPin = 3;  // The pin number of the clock pin.
int dataPin = 4;  // The pin number of the data pin.
int busyPin = 5;  // The pin number of the busy pin.

/*
Create an instance of the Wtv020sd16p class.
 1st parameter: Reset pin number.
 2nd parameter: Clock pin number.
 3rd parameter: Data pin number.
 4th parameter: Busy pin number.
 */
Wtv020sd16p wtv020sd16p(resetPin,clockPin,dataPin,busyPin);

void setup() {
  //Initializes the module.
  Serial.begin(9600);
  wtv020sd16p.reset();
}

void loop() {
  // play sound file 0
  val = analogRead(0);
  //wtv020sd16p.asyncPlayVoice(5);
  if(val >= 60){
    wtv020sd16p.asyncPlayVoice(5);
    delay(3000);
    wtv020sd16p.asyncPlayVoice(1);
    delay(3000);
    wtv020sd16p.asyncPlayVoice(2);
    delay(3000);
    wtv020sd16p.asyncPlayVoice(6);
    delay(3000);
    wtv020sd16p.stopVoice();
  }
  Serial.println(val);
  //delay(500);  
  

 

}

Credits

Joyce Liu
7 projects • 1 follower
cm2014-fa02
Jaclyn Berry
5 projects • 2 followers
Sahana Rajasekar
5 projects • 5 followers
Maxwell N Rutman
4 projects • 2 followers
Herrrrrrrro World

Comments