13. Jan. 2010
verbogen
In den Weihnachtsferien hatte ich eigentlich vor, einen boxsack zum Eingabegerät umzufunktionieren. Leider habe ich die dafür benötigten Drucksensoren erst heute bekommen, deshalb habe ich mich mit anderen Sensoren und ihren Möglichkeiten beschäftigt.
In der letzten Woche habe ich einige Berichte über die CES in Las Vegas gelesen. Großes Thema dort waren neben unter anderem auch E-Book Lesegeräte. Diese mehr oder weniger flachen Geräte können Texte angenehm lesbar auf ihren Bildschirmen anzeigen und sollen (irgentwann mal) das Buch als medium ablesen. Diese Geräte haben sicher einige Vorteile gegenüber den normalen Büchern, allerdings scheint mir die Nutzung noch etwas gewöhnungsbedürftig. Die E-Book Reader haben im Moment alle noch eine feste Oberfläche, im gegensatz zum Buch, dessen Seiten man verbiegen kann. Verbiegbare Bildschirme sind technisch möglich (wenn im Moment auch noch etwas teuer) und deshalb habe ich mich mit Steuerungsmöglichkeiten von verbiegbaren Oberflächen beschäftigt.
Dazu habe ich mir zwei Biegesensoren besorgt und sie an einem Stück Papierblock befestigt. Meine Biegesensoren können nur Biegung in eine Richtung messen, weshalb ich auf jeder Seite des Blocks einen Sensor angebracht habe. Ich habe ein Stück Block verwendet, um das Papier zu stabiliesieren und um sicherzustellen, dass es wieder in die Ausgangsform zurückgeht.
Der arduino Code
int XPin = 0; int YPin = 1; void setup() { Serial.begin(9600); pinMode(YPin, INPUT); } void loop() { Serial.println(map(analogRead(YPin), 0, 1024, 0, 100)); Serial.println(map(analogRead(XPin), 0, 1024, 101, 200)); delay(50); }
Der Processing Code (diesen Artikel zum Thema Maps in Processing sollte man ich vorher anschauen)
import processing.serial.*; Serial myPort; int upperCounter = 0; int lowerCounter = 0; //mode: 0=start, 1=map, 2=text, 3=draw int mode = 1; PFont font; //map specs InteractiveMap map; ZoomButton out = new ZoomButton(5,5,14,14,false); ZoomButton in = new ZoomButton(22,5,14,14,true); PanButton up = new PanButton(14,25,14,14,UP); PanButton down = new PanButton(14,57,14,14,DOWN); PanButton left = new PanButton(5,41,14,14,LEFT); PanButton right = new PanButton(22,41,14,14,RIGHT); // all the buttons in one place, for looping: Button[] buttons = {in, out, up, down, left, right}; boolean gui = false; void setup() { size(1300, 800); smooth(); font = createFont("Helvetica", 12); //serial stuff myPort = new Serial(this, Serial.list()[0], 9600); myPort.bufferUntil('\n'); //map setup //http://maps.google.com/maps?f=q&source=s_q&hl=de&geocode=&q=W%C3%BCrzburg&sll=40.580585,-42.890625&sspn=37.44158,80.419922&ie=UTF8&hq=&hnear=W%C3%BCrzburg,+Bayern,+Deutschland&ll=49.788783,9.93284&spn=0.000977,0.002454&t=h&z=19 map = new InteractiveMap(this, new Microsoft.AerialProvider()); map.setCenterZoom(new Location(49.789, 9.933), 3); addMouseWheelListener(new java.awt.event.MouseWheelListener() { public void mouseWheelMoved(java.awt.event.MouseWheelEvent evt) { mouseWheel(evt.getWheelRotation()); } }); } void draw() { background(80); if(mode == 1) { map.draw(); boolean hand = false; if(gui) { for (int i = 0; i < buttons.length; i++) { buttons[i].draw(); hand = hand || buttons[i].mouseOver(); } } cursor(hand ? HAND : CROSS); if (keyPressed) { if (key == CODED) { if (keyCode == LEFT) { map.tx += 5.0/map.sc; } else if (keyCode == RIGHT) { map.tx -= 5.0/map.sc; } else if (keyCode == UP) { map.ty += 5.0/map.sc; } else if (keyCode == DOWN) { map.ty -= 5.0/map.sc; } } else if (key == '+' || key == '=') { map.sc *= 1.05; } else if (key == '_' || key == '-' && map.sc > 2) { map.sc *= 1.0/1.05; } } if (gui) { textFont(font, 12); Location location = map.pointLocation(mouseX, mouseY); fill(0); noStroke(); rect(5, height-5-g.textSize, textWidth("mouse: " + location), g.textSize+textDescent()); fill(255,255,0); textAlign(LEFT, BOTTOM); text("mouse: " + location, 5, height-5); location = map.pointLocation(width/2, height/2); fill(0); noStroke(); float rw = textWidth("map: " + location); rect(width-5-rw, height-5-g.textSize, rw, g.textSize+textDescent()); fill(255,255,0); textAlign(RIGHT, BOTTOM); text("map: " + location, width-5, height-5); /* location = new Location(51.500, -0.126); Point2f p = map.locationPoint(location); fill(0,255,128); stroke(255,255,0); ellipse(p.x, p.y, 10, 10); */ } } smooth(); } void keyReleased() { if (key == 'g' || key == 'G') { gui = !gui; } else if (key == 's' || key == 'S') { save("modest-maps-app.png"); } else if (key == 'z' || key == 'Z') { map.sc = pow(2, map.getZoom()); } else if (key == ' ') { map.sc = 2.0; map.tx = -128; map.ty = -128; } } void mouseDragged() { boolean hand = false; if(gui) { for (int i = 0; i < buttons.length; i++) { hand = hand || buttons[i].mouseOver(); if (hand) break; } } if(!hand) { map.mouseDragged(); } } void mouseWheel(int delta) { if (delta > 0) { map.sc *= 1.05; } else if (delta < 0) { map.sc *= 1.0/1.05; } } void mouseClicked() { if (in.mouseOver()) { map.zoomIn(); } else if (out.mouseOver()) { map.zoomOut(); } else if (up.mouseOver()) { map.panUp(); } else if (down.mouseOver()) { map.panDown(); } else if (left.mouseOver()) { map.panLeft(); } else if (right.mouseOver()) { map.panRight(); } } class Button { float x, y, w, h; Button(float x, float y, float w, float h) { this.x = x; this.y = y; this.w = w; this.h = h; } boolean mouseOver() { return (mouseX > x && mouseX < x + w && mouseY > y && mouseY < y + h); } void draw() { stroke(80); fill(mouseOver() ? 255 : 220); rect(x,y,w,h); } } class ZoomButton extends Button { boolean in = false; ZoomButton(float x, float y, float w, float h, boolean in) { super(x, y, w, h); this.in = in; } void draw() { super.draw(); stroke(0); line(x+3,y+h/2,x+w-3,y+h/2); if (in) { line(x+w/2,y+3,x+w/2,y+h-3); } } } class PanButton extends Button { int dir = UP; PanButton(float x, float y, float w, float h, int dir) { super(x, y, w, h); this.dir = dir; } void draw() { super.draw(); stroke(0); switch(dir) { case UP: line(x+w/2,y+3,x+w/2,y+h-3); line(x-3+w/2,y+6,x+w/2,y+3); line(x+3+w/2,y+6,x+w/2,y+3); break; case DOWN: line(x+w/2,y+3,x+w/2,y+h-3); line(x-3+w/2,y+h-6,x+w/2,y+h-3); line(x+3+w/2,y+h-6,x+w/2,y+h-3); break; case LEFT: line(x+3,y+h/2,x+w-3,y+h/2); line(x+3,y+h/2,x+6,y-3+h/2); line(x+3,y+h/2,x+6,y+3+h/2); break; case RIGHT: line(x+3,y+h/2,x+w-3,y+h/2); line(x+w-3,y+h/2,x+w-6,y-3+h/2); line(x+w-3,y+h/2,x+w-6,y+3+h/2); break; } } } void serialEvent (Serial myPort) { // get the ASCII string: String inString = myPort.readStringUntil('\n'); if (inString != null) { inString = trim(inString); float inByte = float(inString); //println(inByte); if(inByte < 100) { if(inByte < 50) { if(upperCounter < 1) { upperCounter++; //println("UPPER" + upperCounter); } else { map.sc *= map(inByte, 15, 36, 1.3, 1.00); //map.zoomIn(); upperCounter = 0; println("ZOOM IN"); } } } else if(inByte > 100 && inByte < 155 ) { if( inByte < 135) { if(lowerCounter < 1) { lowerCounter++; //println("LOWER" + lowerCounter); } else { //map.zoomOut(); map.sc *= 1.0/map(inByte, 115, 137, 1.3, 1.00); lowerCounter = 0; println("ZOOM OUT"); } } } } }




Kommentare geschlossen
Die Kommentarfunktion wurde für diesen Eintrag deaktiviert.