Was working better earlier but the tilt switch sometimes refuses to work without me flicking it angrily. This is a concept for a digital book that powers an electronic paper screen with each turn of the page (in this case an LED). Pages are refreshed with a combination of a tilt switch and motor input. The Processing display has been edited out of the video because of inconsistencies. Arduino:
/*
* Digital Book Reader
* State Machine
* Spring 2008
*
* Nadeem Haidary
*/
//LIBRARIES
//GLOBAL VARIABLES
//pins
int motorPin = 0; // motor is connected to pin 0
int LEDPin = 9; // LED is connected to pin 9
int tiltPin = 8; // tilt switch is connected to pin 8
int motorValue; // the value read from the motor
int tiltValue; // the value read from the tilt switch
int currentTilt; // the current tilt value
int previousTilt; // the state of the tilt switch
int x = 0;
//---SETUP-------------------------------------------------------------->
void setup() {
pinMode(motorPin, INPUT); // Set the motor pin as an input
pinMode(LEDPin, OUTPUT); // Set the LED pin as an output
pinMode(tiltPin, INPUT); // Set the tilt pin as an input
//currentTilt = digitalRead(tiltPin);
previousTilt = digitalRead(tiltPin);
Serial.begin(9600); // Start serial communications
}
//---LOOP--------------------------------------------------------------->
void loop(){
motorValue = analogRead(motorPin); // Read the motor pin as an analog input
//Serial.println(motorValue);
analogWrite(LEDPin, motorValue);
currentTilt = digitalRead(tiltPin);
//Serial.println(currentTilt);
//delay(100);
//Serial.println(0);
if (motorValue > 30) {
Serial.println ("Page" + x);
//Serial.print(1, BYTE); // send 1 to Processing
previousTilt = currentTilt;
x++;
}
else { // If the switch is not ON,
//Serial.print(0, BYTE); // send 0 to Processing
}
}
Processing:
/*
* Digital Book Reader
* State Machine
* Spring 2008
*
* Nadeem Haidary
*/
import processing.serial.*;
PFont font;
Serial port; // Create object from Serial class
int val; // Data received from the serial port
int x = 0;
void setup() {
size (400, 600);
background (200);
fill (0);
frameRate(10);
println(Serial.list()); // Set up the serial communication
port = new Serial(this, Serial.list()[1], 9600); // Open the port that the board is connected to (in this case COM4 = [1])
// and use the same speed (9600 bps)
font = loadFont("BookAntiqua-BoldItalic-48.vlw");
}
void draw() {
textFont(font, 48);
text(x, 100, 100);
if (0 < port.available()) { // If data is available,
val = port.read(); // read it and store it in val
}
if (val == 1) {
x++;
background (200);
}
}





