Week
14
: Interface and Application Programming (May 6) 1. Vimeo Links : One, Two 2. Assignments : Write an application that interfaces with an input &/or output device 3. Tryout. A. Before I start, I searched the web on Processing IDE. B. The references of the processing helped alot with basic coding. https://processing.org/reference/ C. I wanted to use the button board that I made before as an input. D. I surfed the web looking for the tutorials and I found nice work done in 2014. E. She made a nice work that I could learn from and it shows the dissemnination of the fabacademy well. http://fabacademy.org/archives/2014/students/pareschi.emma/classes_wk15.html F. I used Arduino IDE to monitor the serial port. However, I could not program the board because continuous error saying the board is not connected. I used the Fab ISP and it worked well. I think the FTDI is broken. "avrdude: Error: Could not find USBtiny device (0x1781/0xc9f)" G. Programmed with Fab ISP and serial port is connected with the broken FTDI creating continous signal. H. However, it stopped signal when the button is pressed. I. I modified the Processing code in usb serial port and making rectangles related to the serial port. 1. myPort=new Serial(this,"/dev/tty.usbserial-A5025URR",9600); 2. rect(xPos,xPos,xPos,-xPos); rect(-xPos,-xPos,xPos,-xPos); J. At the end, here is the result. 4. Codes A. Arduino const int buttonPin = 24; const int ledPin = 17; int buttonState = 0; void setup() { pinMode(ledPin, OUTPUT); pinMode(buttonPin, INPUT); } void loop(){ buttonState = digitalRead(buttonPin); if (buttonState == HIGH) { digitalWrite(ledPin, HIGH); } else { digitalWrite(ledPin, LOW); } } B.Processing import processing.serial.*; Serial myPort; int xPos = 1; void setup () { size(500,500); myPort=new Serial(this,"/dev/tty.usbserial-A5025URR",9600); myPort.bufferUntil('\n'); background(255,0,102); } void draw () { } void serialEvent (Serial myPort) { String inString = myPort.readStringUntil('\n'); if (inString != null) { inString = trim(inString); float inByte = float(inString); inByte = map(inByte, 0, 1023, 0, height); stroke(153,255,51); rect(xPos,xPos,xPos,-xPos); rect(-xPos,-xPos,xPos,-xPos); if (xPos >= width) { xPos = -xPos; background(255,0,102); } xPos++; } } |
|