Arduino

L’Álex Posadas ha presentat el projecte Arduino.

Hem vist la nova versió del software d’Arduino, i el nou Arduino mini i el corresponent adaptador usb mini

També hem vist la guia de profesors per ensenyar Arduino a la ESO, amb la seva referència.

Pàgina d’Arduino

Aquí sota teniu la llista de correu i el codi on vam veure a la presentació:

lista de correo del “interaction and electronic lab”

http://intranet.hangar.org/mailman/listinfo/lab

codigo de processing y arduino para el ejemplo de la clase:

___________________________________________________________________

//// ARDUINO ////
// Example to send data to processing or another software…
// by Alex Posada

int potPin = 0; // select the input pin for the potentiometer
int ledPin = 13; // select the pin for the LED
int val = 0; // variable to store the value coming from the sensor
int val_prev=0;

void setup() {
pinMode(ledPin, OUTPUT); // declare the ledPin as an OUTPUT
Serial.begin(9600); // serial port to 9600 bauds
}

void loop() {

    val = analogRead(potPin)/4; // read the value from the sensor
val = (val + val_prev)/2; // low pass filter
if(val!= val_prev){ // if value is different
val_prev = val; // update val_previo
Serial.print(val, BYTE); // print the value to the serial port
digitalWrite(ledPin, HIGH); // turn the ledPin on
delay(10); // stop the program for some time
digitalWrite(ledPin, LOW); // turn the ledPin off
delay(10); // stop the program for some time
}
}

_________________________________________________________________

//// PROCESSING ////
// Example to receive data from Arduino by serial port // by Alex Posada

import processing.serial.*;

Serial port; // The serial port
int xpos, ypos; // Starting position of the ball

void setup() {
size(256, 256); // Stage size
noStroke(); // No border on the next thing drawn
// Set the starting position of the ball (middle of the stage)
xpos = width/2;
ypos = height/2;

    println(Serial.list());
port = new Serial(this, Serial.list()[2], 9600); // [2] is my 3rd serial port }

void draw() {
background(255);
fill(0);
smooth();

        while (port.available() > 0)
serialEvent(port.read());

            ellipse(xpos, 100, 50, 50);
}

void serialEvent(int serial)
{
xpos = serial;
println(serial);
}

Leave a Reply

You must be logged in to post a comment.