Skip to content

Instantly share code, notes, and snippets.

@madbunnykim
Last active October 25, 2017 07:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save madbunnykim/f1d072ce67008bbd4482946130cb3e69 to your computer and use it in GitHub Desktop.
Save madbunnykim/f1d072ce67008bbd4482946130cb3e69 to your computer and use it in GitHub Desktop.
Running pumpkin
#include "ESP8266WiFi.h"
// WiFi parameters to be configured
//const char* ssid = "RZ2Q8";
//const char* password = "9G9XP2ZBLDYHFQH2";
int photocellPin = 0;
int photocellValue = 0;
int motorPin = 12; //GI012
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(motorPin, OUTPUT);
// WiFi.begin(ssid, password);
// while (WiFi.status() != WL_CONNECTED) {
// delay(500);
// Serial.print(".");
// }
// //print a new line, then print WiFi connected and the IP address
// Serial.println("");
// Serial.println("WiFi connected");
// // Print the IP address
// Serial.println(WiFi.localIP());
}
void loop() {
// put your main code here, to run repeatedly:
photocellValue = analogRead(photocellPin);
Serial.println(photocellValue);
if (photocellValue < 60) {
digitalWrite(motorPin, HIGH);
}
else{
digitalWrite(motorPin, LOW);
}
}
let serial;
let latestData;
let lefteye;
let righteye;
let nose;
let mouth;
let song;
let playing = 0;
function setup() {
createCanvas(700, 700);
song.loop();
if (latestData < 60) {
song.pause();
playing = 0;
}
else {
if (playing == 0){
song.play();
playing = 1;
}
}
serial = new p5.SerialPort();
serial.open("/dev/cu.usbmodem1410");
serial.on('data', gotData);
}
function preload() {
lefteye = loadImage('images/lefteye.png');
righteye = loadImage('images/righteye.png');
nose = loadImage('images/nose.png');
mouth = loadImage('images/mouth.png');
song = loadSound('pumpkinsong.mp3');
}
function gotData() {
let currentString = serial.readLine();
trim(currentString);
if (!currentString) return;
//console.log(currentString);
latestData = currentString;
}
function draw() {
// let v = random(-5,5);
// let latestData = v;
background(0);
imageMode(CENTER);
let mappedVar = map(latestData,30,150,100,0);
let v = mappedVar;
image(lefteye,width/2-150+(v/8),height/2-150,v,v);
image(righteye,width/2+150-(v/8),height/2-150,v,v);
image(nose,width/2,height/2-40,v+50,v+50);
translate(10);
rotate(radians(frameCount%10));
image(mouth,width/2+v/2,height/2+100,400,200);
}
// function mousePressed() {
// if ( song.isPlaying() ) {
// song.pause();
// } else {
// song.play();
// }
// }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment