Skip to content

Instantly share code, notes, and snippets.

@CalvinLogan
Last active May 24, 2021 06:23
Show Gist options
  • Save CalvinLogan/b3b182b3ac30f1e349d39f5c9dc174d8 to your computer and use it in GitHub Desktop.
Save CalvinLogan/b3b182b3ac30f1e349d39f5c9dc174d8 to your computer and use it in GitHub Desktop.
let potLeft = 0;
let potRight = 0;
let slider = 0;
let button = 0;
//where data comes in and we can fuck it up
//data comes in as a string
function gotData() {
let currentString = serial.readLine();//reading the code, looking for //commas and line breaks
if(currentString.length > 0) {
let sensorArray = split(currentString, ","); //splits string at //delimiter
slider = Number(sensorArray[0]);
potLeft = Number(sensorArray[1]);
potRight = Number(sensorArray[2]);
button = Number(sensorArray[3]);
}
}
function draw() {
background(255,255,255);
var colorLibrary = ["LavenderBlush","LemonChiffon","Lavender","LightCyan","LightPink","PaleTurquoise","Pink","Plum","PowderBlue"];
sliderColor = floor(map(slider, 30, 1023, 0, 8)); //maps the outputs of the slider to the range of inputs in our array
thisColor = colorLibrary[sliderColor]; //gets the color from the colorLibrary based on the slider value
colorString = (String(thisColor)); //converts that value into a string that fill can read
fill(colorString); //sets the fill color of the ball to the color from the colorLibrary
noStroke();
x = map(potLeft,0,1023,0,windowWidth); //takes in the readings from the right potentiometer and maps them to the width of the window
y = map(potRight,0,1023,0,windowHeight); //takes in the readings from the left potentiometer and maps them to the heigh of the window
ellipse(x,y,50,50); //makes a circle at the x and y positions set by the remapped potentiometer readings
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment