Skip to content

Instantly share code, notes, and snippets.

View bevchou's full-sized avatar

Beverly Chou bevchou

View GitHub Profile
//keep track of gifs
let currentGif; //the file path
let image; //the actual image
//API info
let APIkey = "3GGsEajJUSgykXGpw4EeN6QYY5w5Ve7G";
let numGif = 25;
let queryLeft = "cat";
let queryRight = "dog";
let giphyLeftData;
let giphyMiddleData;
@bevchou
bevchou / P Comp 10_22 Midterm Game p5 Sound Code Working.js
Last active January 30, 2018 07:17
Takes serial inputs from Arduino and plays sounds to match buttons press & when you lose
// Declare a "SerialPort" object
let serial;
let latestData = "waiting for data";
//sounds
let sounds = [];
//incoming data from arduino
let arduinoData = [];
let activeSide;
let interval;
//logic for when to play sound
//LED Pins
int LEDPins[] = {5, 6, 7, 8, 9};
//Switch Pins
int switchPins [] = {12, 11, 2, 3, 4};
//sides
int activeSide;
int activeSwitchState;
int lastActiveSwitchState;
//LED Pins
int LEDPins[] = {5, 6, 7, 8, 9};
//Switch Pins
int switchPins [] = {12, 11, 2, 3, 4};
//sides
int activeSide;
int activeSwitchState;
int lastActiveSwitchState;
@bevchou
bevchou / P Comp 10_21 Midterm Game - LED Random.ino
Last active January 30, 2018 07:18
Logic to active game and light up a random LED when the activate game button is pressed
//LED Pins
int LEDPins[] = {5, 6, 7, 8, 9};
void setup() {
Serial.begin(9600);
//LEDS
pinMode(LEDPins[0], OUTPUT);
pinMode(LEDPins[1], OUTPUT);
pinMode(LEDPins[2], OUTPUT);
pinMode(LEDPins[3], OUTPUT);
// Declare a "SerialPort" object
let serial;
let latestData = "waiting for data";
//sensor data
let factor1, factor2;
let sensorValue = [];
function setup() {
// Instantiate our SerialPort object
serial = new p5.SerialPort();
@bevchou
bevchou / P Comp 10_18 Serial Connection - Reading Two Values From Arduino
Created October 18, 2017 06:32
Outputs the values as a string with sensor values separated by commas on each line
// the setup routine runs once when you press reset:
void setup() {
Serial.begin(9600);
}
void loop() {
//photoresistor on A0 pin
int photoresValue = analogRead(A0);
photoresValue *= 0.25;
Serial.print(photoresValue);
@bevchou
bevchou / ICM HW6 Show and Delete Gifs
Created October 17, 2017 09:38
This code isn't the full code- just sections relating to displaying the gifs
function setup() {
//starter image
image = createImg("welcome.gif");
image.class('gif');
//remove and then show new gif
button.mousePressed(removeGif);
button.mouseReleased(showGif);
}
function showGif() {
@bevchou
bevchou / ICM HW6 File Path Into Array
Last active October 17, 2017 09:35
Instead of preloading images, I used the file paths instead
//this code goes in the setup
for (let i = 0; i < numGif; i++) {
catGif.push("/cat-gifs/cat" + i + ".gif");
catDogGif.push("/cat-dog-gifs/catdog" + i + ".gif");
dogGif.push("/dog-gifs/dog" + i + ".gif");
}
function preload() {
for (let i = 0; i < numGif; i++) {
catGif.push(loadImage("/cat-gifs/cat" + i + ".gif"));
catDogGif.push(loadImage("/cat-dog-gifs/catdog" + i + ".gif"));
dogGif.push(loadImage("/dog-gifs/dog" + i + ".gif"));
}
}