I’ll be using my Pcomp project to talk about the computational approach used to make it work. For context, I’m working together with Helen to create an interactive pop-up book. The main premise behind this project are a group of conditional statements that checks for various conditions. We figured this would be the best way to approach this project as it’ll ensure that the book will be able to respond to individual pages.
For a start, we need a method to let the Arduino know which page we are on. We used a photo-resistor which responds to light and we used that value to depict which page we are on. This was the first step for us as we needed a way to group the functionalities within the individual pages so that they only run at each given page. This was achieved computationally by checking the 5 photo-resistors, if they each goes past a certain range, that means the page is open. They were then grouped as a function so we could just reuse this function as “checkPageOpen”. It will also send a key code of the number to p5.
Sample code:
//p[i] value, where i is individual photoresistor value
//threshold is set at 50
//checks if the indivudal value is greater than 50, if it is, that page is open
int checkPageOpen(){
if (p5Value > threshold) {
pageOpen = 5;
}
else if (p4Value > threshold) {
pageOpen = 4;
}
else if (p3Value > threshold){
pageOpen = 3;
}
else if (p2Value > threshold){
pageOpen = 2;
}
else if (p1Value > threshold){
pageOpen = 1;
} else {
pageOpen = 0;
}
}
With the above function, we used checkPageOpen to check which page our book is currently on, and based on the page number, we have different functionalities within that page.
Example code:
void loop(){
checkPageOpen();
if (pageOpen == 2){
//function for page 2 goes here
}
if (pageOpen == 3){
//function for page 3 goes here
}
Other than the physical aspect to it, we also incorporated media elements into the project — we used Arduino as a keyboard to send a key code to p5 that will respond to individual pages on the book. We also decided to use p5 because of its media functions and how it could play video and audio.
Link to full sketch: https://editor.p5js.org/Chris-ITP/sketches/Nw9yGUEbH
Example code in p5 to check with page it is at now.
function keyPressed() {
// Book is closed
if (key === "0") {
currentPage = 0;
}
// PAGE 1
if (key === "1") {
currentPage = 1;
}
// PAGE 2
if (key === "2") {
currentPage = 2;
}
// PAGE 3
if (key === "3") {
currentPage = 3;
}
// PAGE 4
if (key === "4") {
currentPage = 4;
}
// PAGE 5
if (key === "5") {
currentPage = 5;
}
With the same concept, they are then used in the draw loop based on the page number to write out the story. The only exception is page 3 where it has another lay of conditionals that play the sounds depending on which key code is sent out (alphabets instead of numbers).
Overall, the idea of using conditionals for our project worked really well because the foundations of the project was about checking which page the book is on, and if it’s on this page do a bunch of functions. It was also interesting to see the same concept applied onto p5 which worked very well in our favor as a media player.