gaztea tech 2015: 3. processing y firmata

13
3. PROCESSING Y FIRMATA Introducción GAZTEA TECH 2015 ROBÓTICA Svet Ivantchev Jon Agüero

Upload: svet-ivantchev

Post on 09-Aug-2015

65 views

Category:

Education


1 download

TRANSCRIPT

3. PROCESSING Y FIRMATAIntroducción

GAZTEA TECH 2015ROBÓTICA

Svet IvantchevJon Agüero

PROCESSING

void setup() { size(300, 300);}

void draw() { ellipse(mouseX, mouseY, 50, 50);}

void setup() { size(300, 300);}

void draw() { if (mousePressed) { fill(0); } else { fill(200,100,200); } ellipse(mouseX, mouseY, 50, 50);}

PROCESSING + ARDUINO

PC - Processing Arduino - Firmata

Servos, LEDs, …USB pins

ARDUINO

Instalar la librería Arduino (Firmata): Sketch > Import Library … > Add Library …

import processing.serial.*;import cc.arduino.*;

Arduino arduino;

void setup() { println(Arduino.list()); arduino = new Arduino(this, Arduino.list()[0], 57600); arduino.pinMode(6, Arduino.OUTPUT);}

void draw() { int potVal; potVal = arduino.analogRead(0); arduino.digitalWrite(6, Arduino.HIGH); delay(potVal); arduino.digitalWrite(6, Arduino.LOW); delay(potVal); }

SU TURNO

• Dibujar un circulo en la posición del raton. El diámetro del circulo depende de la posición del potenciómetro conectado al Arduino

SERVO CON FIRMATA

import processing.serial.*;import cc.arduino.*;

Arduino arduino;

void setup() { println(Arduino.list()); arduino = new Arduino(this, Arduino.list()[0], 57600); arduino.pinMode(4, Arduino.SERVO);}

void draw() { arduino.servoWrite(4, 85);}

LA TEMPERATURA EN BILBAOJSONObject weather; void setup() { weather = loadJSONObject("http://api.openweathermap.org/data/2.5/weather?id=3128026");} void draw() { int temp = get_temp(weather)-272; String city = get_city(weather); String main_weather = get_main_weather(weather); println(city); println(temp); println(main_weather); } int get_temp(JSONObject json) { JSONObject all = json.getJSONObject("main"); int temp = all.getInt("temp"); return temp;} String get_city(JSONObject json) { String city = json.getString("name"); return city;} String get_main_weather(JSONObject json) { JSONArray all = json.getJSONArray("weather"); JSONObject values = all.getJSONObject(0); String main_weather = values.getString("main"); return main_weather;}

SU TURNO

• Termómetro analógico: el servo indica la temperatura; un led rojo se enciende si la temperatura supera los 30 grados