Total Pageviews
Showing posts with label INTERACTIVE ART. Show all posts
Showing posts with label INTERACTIVE ART. Show all posts
Wednesday, 7 October 2015
Monday, 17 November 2014
arduino14
void setup() {
Serial.begin(9600);
}
void loop() {
Serial.write(analogRead(A0)/4);
delay(1);
}
import processing.serial.*;
Serial myPort;
PImage logo;
int bgcolor = 0;
void setup() {
colorMode(HSB, 255);
logo = loadImage("http://arduino.cc/logo.png");
size(logo.width, logo.height);
println("Available serial ports:");
println(Serial.list());
myPort = new Serial(this, Serial.list()[5], 9600);
}
void draw() {
if(myPort.available() > 0) {
bgcolor = myPort.read();
println(bgcolor);
}
background(bgcolor, 255, 255);
image(logo, 0, 0);
}
Serial.begin(9600);
}
void loop() {
Serial.write(analogRead(A0)/4);
delay(1);
}
import processing.serial.*;
Serial myPort;
PImage logo;
int bgcolor = 0;
void setup() {
colorMode(HSB, 255);
logo = loadImage("http://arduino.cc/logo.png");
size(logo.width, logo.height);
println("Available serial ports:");
println(Serial.list());
myPort = new Serial(this, Serial.list()[5], 9600);
}
void draw() {
if(myPort.available() > 0) {
bgcolor = myPort.read();
println(bgcolor);
}
background(bgcolor, 255, 255);
image(logo, 0, 0);
}
Arduino13-feely Lamp
#include <CapacitiveSensor.h>
CapacitiveSensor capSensor = CapacitiveSensor(4,2);
int threshold = 1000;
const int ledPin = 12;
void setup() {
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
}
void loop() {
long sensorValue = capSensor.capacitiveSensor(30);
Serial.println(sensorValue);
if(sensorValue > threshold) {
digitalWrite(ledPin, HIGH);
}
else {
digitalWrite(ledPin, LOW);
}
delay(10);
}
CapacitiveSensor capSensor = CapacitiveSensor(4,2);
int threshold = 1000;
const int ledPin = 12;
void setup() {
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
}
void loop() {
long sensorValue = capSensor.capacitiveSensor(30);
Serial.println(sensorValue);
if(sensorValue > threshold) {
digitalWrite(ledPin, HIGH);
}
else {
digitalWrite(ledPin, LOW);
}
delay(10);
}
ARDUINO12-
#include <Servo.h>
Servo servo9;
const int piezo = A0;
const int switchPin = 2;
const int yellowLed = 3;
const int greenLed = 4;
const int redLed = 5;
int knockVal;
int switchVal;
const int quietKnock = 10;
const int loudKnock = 100;
boolean locked = false;
int numberOfKnocks = 0;
void setup() {
servo9.attach(9);
pinMode(yellowLed, OUTPUT);
pinMode(greenLed, OUTPUT);
pinMode(redLed, OUTPUT);
pinMode(switchPin, INPUT);
Serial.begin(9600);
digitalWrite(greenLed, HIGH);
servo9.write(0);
Serial.println("The box is unlocked!");
}
void loop() {
if(locked == false) {
switchVal = digitalRead(switchPin);
if(switchVal == HIGH) {
locked = true;
digitalWrite(greenLed, LOW);
digitalWrite(redLed, HIGH);
servo9.write(90);
Serial.println("The box is locked!");
delay(1000);
}
}
if(locked == true) {
knockVal = analogRead(piezo);
if(numberOfKnocks < 3 && knockVal > 0) {
if(checkForKnock(knockVal) == true) {
numberOfKnocks++;
}
Serial.print(3 - numberOfKnocks);
Serial.println(" more knocks to go");
}
if(numberOfKnocks >= 3) {
locked = false;
servo9.write(0);
delay(20);
digitalWrite(greenLed, HIGH);
digitalWrite(redLed, LOW);
Serial.println("The box is unlocked!");
}
}
}
boolean checkForKnock(int value) {
if(value > quietKnock && value < loudKnock) {
digitalWrite(yellowLed, HIGH);
delay(50);
digitalWrite(yellowLed, LOW);
Serial.print("Valid knock of value ");
Serial.println(value);
return true;
}
else {
Serial.print("Bad knock value ");
Serial.println(value);
return false;
}
}
Servo servo9;
const int piezo = A0;
const int switchPin = 2;
const int yellowLed = 3;
const int greenLed = 4;
const int redLed = 5;
int knockVal;
int switchVal;
const int quietKnock = 10;
const int loudKnock = 100;
boolean locked = false;
int numberOfKnocks = 0;
void setup() {
servo9.attach(9);
pinMode(yellowLed, OUTPUT);
pinMode(greenLed, OUTPUT);
pinMode(redLed, OUTPUT);
pinMode(switchPin, INPUT);
Serial.begin(9600);
digitalWrite(greenLed, HIGH);
servo9.write(0);
Serial.println("The box is unlocked!");
}
void loop() {
if(locked == false) {
switchVal = digitalRead(switchPin);
if(switchVal == HIGH) {
locked = true;
digitalWrite(greenLed, LOW);
digitalWrite(redLed, HIGH);
servo9.write(90);
Serial.println("The box is locked!");
delay(1000);
}
}
if(locked == true) {
knockVal = analogRead(piezo);
if(numberOfKnocks < 3 && knockVal > 0) {
if(checkForKnock(knockVal) == true) {
numberOfKnocks++;
}
Serial.print(3 - numberOfKnocks);
Serial.println(" more knocks to go");
}
if(numberOfKnocks >= 3) {
locked = false;
servo9.write(0);
delay(20);
digitalWrite(greenLed, HIGH);
digitalWrite(redLed, LOW);
Serial.println("The box is unlocked!");
}
}
}
boolean checkForKnock(int value) {
if(value > quietKnock && value < loudKnock) {
digitalWrite(yellowLed, HIGH);
delay(50);
digitalWrite(yellowLed, LOW);
Serial.print("Valid knock of value ");
Serial.println(value);
return true;
}
else {
Serial.print("Bad knock value ");
Serial.println(value);
return false;
}
}
ARDUINO11-Crystal Ball
THE CODE FOR 11
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
const int switchPin = 6;
int switchState = 0;
int prevSwitchState = 0;
int reply;
void setup() {
lcd.begin(16, 2);
pinMode(switchPin, INPUT);
lcd.print("Ask the");
lcd.setCursor(0, 1);
lcd.print("Crystal Ball!");
}
void loop() {
switchState = digitalRead(switchPin);
if(switchState != prevSwitchState) {
if(switchState == LOW) {
reply = random(8);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("The Ball says: ");
lcd.setCursor(0, 1);
switch(reply) {
case 0:
lcd.print("Yes");
break;
case 1:
lcd.print("Most likely");
break;
case 2:
lcd.print("Certainly");
break;
case 3:
lcd.print("Outlook good");
break;
case 4:
lcd.print("Unsure");
break;
case 5:
lcd.print("Ask again");
break;
case 6:
lcd.print("Doubtful");
break;
case 7:
lcd.print("No");
break;
}
}
}
prevSwitchState = switchState;
}
Sunday, 16 November 2014
ARDUINO10 -Zoetrope- basics
const int controlPin2 = 3;
const int enablePin = 9;
const int directionSwitchPin = 4;
const int onOffSwitchStateSwitchPin = 5;
const int potPin = A0;
int onOffSwitchState = 0;
int previousOnOffSwitchState = 0;
int directionSwitchState = 0;
int previousDirectionSwitchState = 0;
int motorEnabled = 0;
int motorSpeed = 0;
int motorDirection = 1;
void setup() {
pinMode(directionSwitchPin, INPUT);
pinMode(onOffSwitchStateSwitchPin, INPUT);
pinMode(controlPin1, OUTPUT);
pinMode(controlPin2, OUTPUT);
pinMode(enablePin, OUTPUT);
digitalWrite(enablePin, LOW);
}
void loop() {
onOffSwitchState = digitalRead(onOffSwitchStateSwitchPin);
delay(1);
directionSwitchState = digitalRead(directionSwitchPin);
motorSpeed = analogRead(potPin)/4;
if(onOffSwitchState != previousOnOffSwitchState) {
if(onOffSwitchState == HIGH) {
motorEnabled = !motorEnabled;
}
}
if (directionSwitchState != previousDirectionSwitchState) {
if (directionSwitchState == HIGH) {
motorDirection = !motorDirection;
}
}
if (motorDirection = 1) {
digitalWrite(controlPin1, HIGH);
digitalWrite(controlPin2, LOW);
}
else {
digitalWrite(controlPin1, LOW);
digitalWrite(controlPin2, HIGH);
}
if (motorEnabled == 1) {
analogWrite(enablePin, motorSpeed);
}
else {
analogWrite(enablePin, 0);
}
previousDirectionSwitchState = directionSwitchState;
previousOnOffSwitchState = onOffSwitchState;
}
ARDUINO08-DIGITAL HOURGLASS
const int switchPin = 8;
unsigned long previousTime = 0;
int switchState = 0;
int prevSwitchState = 0;
int led = 2;
long interval = 3000;
void setup() {
for(int x = 2; x < 8; x++) {
pinMode(x, OUTPUT);
}
pinMode(8, INPUT);
Serial.begin(9600);
}
void loop() {
unsigned long currentTime = millis();
if(currentTime - previousTime > interval){
previousTime = currentTime;
digitalWrite(led, HIGH);
led++;
if(led == 7){
}
}
switchState = digitalRead(switchPin);
Serial.println(switchState);
if(switchState != prevSwitchState){
for(int x = 2; x < 8; x++){
digitalWrite(x, LOW);
}
led = 2;
previousTime = currentTime;
}
prevSwitchState = switchState;
}
unsigned long previousTime = 0;
int switchState = 0;
int prevSwitchState = 0;
int led = 2;
long interval = 3000;
void setup() {
for(int x = 2; x < 8; x++) {
pinMode(x, OUTPUT);
}
pinMode(8, INPUT);
Serial.begin(9600);
}
void loop() {
unsigned long currentTime = millis();
if(currentTime - previousTime > interval){
previousTime = currentTime;
digitalWrite(led, HIGH);
led++;
if(led == 7){
}
}
switchState = digitalRead(switchPin);
Serial.println(switchState);
if(switchState != prevSwitchState){
for(int x = 2; x < 8; x++){
digitalWrite(x, LOW);
}
led = 2;
previousTime = currentTime;
}
prevSwitchState = switchState;
}
ARDUINO07-KEYBOARD INSTRUMENTS
int notes[] = {262, 294, 330, 349};
void setup() {
Serial.begin(9600);
}
void loop() {
int keyVal = analogRead(A0);
Serial.println(keyVal);
if (keyVal == 1023) {
tone(8, notes[0]);
}
else if(keyVal >= 990 && keyVal <= 1010) {
tone(8, notes[1]);
}
else if(keyVal >= 505 && keyVal <= 515) {
tone(8, notes[2]);
}
else if(keyVal >= 5 && keyVal <= 10) {
tone(8, notes[3]);
}
else {
noTone(8);
}
}
void setup() {
Serial.begin(9600);
}
void loop() {
int keyVal = analogRead(A0);
Serial.println(keyVal);
if (keyVal == 1023) {
tone(8, notes[0]);
}
else if(keyVal >= 990 && keyVal <= 1010) {
tone(8, notes[1]);
}
else if(keyVal >= 505 && keyVal <= 515) {
tone(8, notes[2]);
}
else if(keyVal >= 5 && keyVal <= 10) {
tone(8, notes[3]);
}
else {
noTone(8);
}
}
Saturday, 15 November 2014
ARDUINO 06-light theremin
int sensorValue;
int sensorLow = 1023;
int sensorHigh = 0;
const int ledPin = 13;
void setup() {
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, HIGH);
while (millis() < 5000) {
sensorValue = analogRead(A0);
if (sensorValue > sensorHigh) {
sensorHigh = sensorValue;
}
if (sensorValue < sensorLow) {
sensorLow = sensorValue;
}
}
digitalWrite(ledPin, LOW);
}
void loop() {
sensorValue = analogRead(A0);
int pitch = map(sensorValue, sensorLow, sensorHigh, 50, 4000);
tone(8, pitch, 20);
delay(10);
}
ARDUINO 05 MOOD CUE
1. Ορισμός του πυκνωτή - μονάδες χωρητικότητας
Πυκνωτής ονομάζεται η διάταξη εκείνη που
αποτελείται από δύο αγώγιμες πλάκες οι οποίες χωρίζονται μεταξύ τους από κάποιο
μονωτικό υλικό. Οι αγώγιμες πλάκες ονομάζονται οπλισμοί και το μονωτικό υλικό
ονομάζεται διηλεκτρικό. Ο πυκνωτής έχει την ιδιότητα να συγκρατεί στους
οπλισμούς του ηλεκτρικό φορτίο, όταν εφαρμοστεί μια τάση στα άκρα του. Η
ποσότητα του φορτίου που μπορεί να συγκρατήσει ο πυκνωτής εξαρτάται από την
επιφάνεια των οπλισμών του και την απόσταση μεταξύ των οπλισμών. όσο μεγαλύτερη
είναι η επιφάνεια των οπλισμών και όσο μικρότερη η απόσταση των οπλισμών μεταξύ
τους, τόσο μεγαλύτερο φορτίο μπορεί να συγκρατήσει. Το είδος του διηλεκτρικού
υλικού παίζει πολύ μεγάλο ρόλο στην συγκράτηση του φορτίου που εκφράζεται με
τον όρο χωρητικότητα. ’ρα λοιπόν η ικανότητα ενός πυκνωτή να
αποθηκεύει ενέργεια ονομάζεται χωρητικότητα.
Η χωρητικότητα ενός πυκνωτή συμβολίζεται με
το γράμμα C και μονάδα μέτρησής της είναι το Farad.
Επειδή το Farad (F), είναι μεγάλη χωρητικότητα στους πυκνωτές
χρησιμοποιούνται υποδιαιρέσεις του Farad όπως βλέπουμε παρακάτω:
1F=1000mF, 1mF=1000μF, 1μF=1000nF,
1nF=1000pF. Για να είναι ποιο εύκολα κατανοητές οι μονάδες φανταστείτε μια
σκάλα, με κορυφή την μέγιστη μονάδα χωρητικότητας και τελευταία την μικρότερη,
όπως βλέπουμε κατά σειρά παρακάτω: F>mF>μF>nF>pF.
Κάθε
σκάλα που κατεβαίνουμε προς τα κάτω πολλαπλασιάζουμε Χ1000, ενώ όταν
ανεβαίνουμε από κάτω προς τα πάνω διαιρούμε :1000. Έτσι για παράδειγμα ένας
πυκνωτής που είναι 470nF είναι ίσος με 0,47μF, ή ένας πυκνωτής που είναι 2,2nF
είναι ίσος με 2200pF.
#include <Servo.h>
Servo myServo; //Create a new servo
int const potPin = A0; //Analog pin for the potentiometer
int potVal; //Values given by the potentiometer
int angle; //values that will modify the angle of the
servo
void setup() {
myServo.attach(9); //Makes a servo be
controlled by pin 9
Serial.begin(9600); //Initialize Serial monitor
}
void loop() {
potVal = analogRead(potPin); //Giving potVal
the values from the potentiometer
Serial.print("potVal: "); //printing
in Serial monitor the values given by the potentiometer
Serial.print(potVal);
angle = map(potVal, 0, 1023, 0, 179); //mapping
helps to convert the values from the potentiometer (0-1023) to values accepted
to the servo (0-180)
Serial.print(", angle: "); //Printing
out the angle value.
Serial.print(angle);
myServo.write(angle); //Actually making the
servo moving, as the angle value changes.
delay(15); //does all those instructions in 15
milliseconds.
}
ARDUINO 04 COLOR MIXING LAMP
const int greenLEDPin = 9; //Green pin in the RGB LED
const int redLEDPin = 11; //Red pin in the RGB LED
const int blueLEDPin = 10; //Blue pin in the RGB LED
const int redSensorPin = A0; //Photoresistor no. 1
const int greenSensorPin = A1; //Photoresistor no. 2
const int blueSensorPin = A2; //Photoresistor no. 3
int redValue = 0;
int greenValue = 0;
int blueValue = 0;
//These values can only be from 0 to 255.
int redSensorValue = 0;
int greenSensorValue = 0;
int blueSensorValue = 0;
//These values will be reading from the photoresistors.
void setup() {
Serial.begin(9600);
//Set up the RGB LED pins to be OUTPUT.
pinMode(greenLEDPin, OUTPUT);
pinMode(redLEDPin, OUTPUT);
pinMode(blueLEDPin, OUTPUT);
}
void loop() {
//Set up the XXSensorValues to read from the photoresistors.
redSensorValue = analogRead(redSensorPin);
delay(5);
greenSensorValue = analogRead(greenSensorPin);
delay(5);
blueSensorValue = analogRead(blueSensorPin);
delay(5);
//Print on the serial monitor the values given by the photoresistors.
Serial.print("Raw Sensor Values \t Red: ");
Serial.print(redSensorValue);
Serial.print("\t Green: ");
Serial.print(greenSensorValue);
Serial.print("\t Blue: ");
Serial.print(blueSensorValue);
//XXValue can only be from 0 to 255 because they are define the intensity of the pin on the RGB LED.
redValue = redSensorValue/4;
greenValue = greenSensorValue/4;
blueValue = blueSensorValue/4;
//Print on the serial monitor the values that the LED pin is on.
Serial.print("Mapped Sensor Values \t Red: ");
Serial.print(redValue);
Serial.print("\t Green: ");
Serial.print(greenValue);
Serial.print("\t Blue: ");
Serial.print(blueValue);
//analogWrite is used here to write, instead of HIGH(1) or LOW(0), a certain intensity(0-255) that is more precise.
analogWrite(redLEDPin, redValue);
analogWrite(greenLEDPin, greenValue);
analogWrite(blueLEDPin, blueValue);
}
Subscribe to:
Posts (Atom)






















































