The
concept:
I wanted to
come up with a unique concept for this week as you told us that this week the
concept was more important than the code itself, I wanted to develop a concept
first.
Brainstorm:
-
Flowers
-
Changing
seasons
-
Interactive
-
Press
button every time dot appears, keeps going faster
-
Garden
with lanterns, when button press lantern turns on
-
Pumpkin
with lamp, on button press lamp turns brighter until it goes off again
I like the
last idea because it’s almost Halloween! I want to make an image of a pumpkin
and every time the button is pressed the light inside goes brighter until it
goes out again
First step:
No button press is black screen
Second step:
first button press= show pumpkin with little light
Third step:
show pumpkin with more light
Fourth step:
The pumpkin is on fire? Or fourth step is light turns off again and back to
step one. (End)
I started
out by recreating the code and setup we made in class, which prompted an image
on button click, the only difference here is that I want to show a different
image every time the button is pressed. Secondly I created all ‘images’ separately
in processing
The result:
Zip file:
https://drive.google.com/drive/folders/13NKzFQ70zx06CGzw5EsPH1Zn2wHyEnKo?usp=sharingCode:
Processing:
import processing.serial.*;
Serial Port;
int val;
int TurnNum;
int Boom;
PImage img1;
PImage img2;
PImage img3;
PImage img4;
void setup()
{
size(1000, 1000);
printArray(Serial.list());
Port = new Serial(this, Serial.list()[0], 9600);
TurnNum = 0;
Boom = (int) random(150);
img1 = loadImage("1.png");
img2 = loadImage("2.png");
img3 = loadImage("3.png");
img4 = loadImage("4.png");
}
void draw() {
//background(0);
if ( Port.available() > 0) {
val = Port.read();
println("Button Pressed: " + val);
println("Turn Num: " + TurnNum);
println("Boom: " + Boom);
if (TurnNum > Boom){
image(img4,0,0);
}
}
if (val == 0){
fill(0);
}else{
TurnNum = TurnNum + 1;
if (TurnNum >= 10 && TurnNum <=20){
image(img1,0,0);
}
if (TurnNum >= 21 && TurnNum <=30){
image(img2,0,0);
}
if (TurnNum >= 31 && TurnNum <=40){
image(img3,0,0);
}
if (TurnNum >= 41 && TurnNum <=50){
image(img1,0,0);
}
if (TurnNum >= 51 && TurnNum <=60){
image(img2,0,0);
}
if (TurnNum >= 61 && TurnNum <=70){
image(img3,0,0);
}
if (TurnNum >= 71 && TurnNum <=80){
image(img1,0,0);
}
if (TurnNum >= 81 && TurnNum <=90){
image(img2,0,0);
}
if (TurnNum >= 91 && TurnNum <=100){
image(img3,0,0);
}
if (TurnNum >= 101 && TurnNum <=110){
image(img1,0,0);
}
if (TurnNum >= 111 && TurnNum <=120){
image(img2,0,0);
}
if (TurnNum >= 121 && TurnNum <=130){
image(img3,0,0);
}
if (TurnNum >= 131 && TurnNum <=140){
image(img1,0,0);
}
if (TurnNum >= 141 && TurnNum <=150){
image(img2,0,0);
}
}
if (TurnNum >= 10){
}
}
Arduino:
int inputPin = 2;
void setup() {
Serial.begin(9600);
pinMode(inputPin, INPUT);
}
void loop() {
int state = digitalRead(inputPin);
Serial.write(state);
delay(50);
}
Comments
Post a Comment