SHOW:
|
|
- or go back to the newest paste.
| 1 | //arduino code | |
| 2 | ||
| 3 | ||
| 4 | const int analogInPin0 = A0; // Analog input pin that the potentiometer is attached to | |
| 5 | ||
| 6 | ||
| 7 | ||
| 8 | void setup() {
| |
| 9 | Serial.begin(9600); | |
| 10 | } | |
| 11 | ||
| 12 | void loop() {
| |
| 13 | // print the results to the serial monitor: | |
| 14 | Serial.print(analogRead(analogInPin0)); | |
| 15 | Serial.print("\n");
| |
| 16 | delay(100); | |
| 17 | } | |
| 18 | ||
| 19 | ||
| 20 | ||
| 21 | ||
| 22 | ||
| 23 | ||
| 24 | ||
| 25 | //processing arduino 101 | |
| 26 | ||
| 27 | import processing.serial.*; | |
| 28 | ||
| 29 | Serial myPort; // The serial port | |
| 30 | ||
| 31 | float analogPin = 0; | |
| 32 | ||
| 33 | void setup () {
| |
| 34 | // set the window size: | |
| 35 | size(400, 300); | |
| 36 | ||
| 37 | // List all the available serial ports | |
| 38 | // if using Processing 2.1 or later, use Serial.printArray() | |
| 39 | println(Serial.list()); | |
| 40 | ||
| 41 | // I know that the first port in the serial list on my Mac is always my | |
| 42 | // Arduino, so I open Serial.list()[0]. | |
| 43 | // Open whatever port is the one you're using. | |
| 44 | myPort = new Serial(this, Serial.list()[1], 9600); | |
| 45 | ||
| 46 | // don't generate a serialEvent() unless you get a newline character: | |
| 47 | myPort.bufferUntil('\n');
| |
| 48 | } | |
| 49 | ||
| 50 | void draw () {
| |
| 51 | background(255); | |
| 52 | ||
| 53 | ||
| 54 | } | |
| 55 | ||
| 56 | void serialEvent (Serial myPort) {
| |
| 57 | // get the ASCII string: | |
| 58 | String inString = myPort.readStringUntil('\n');
| |
| 59 | ||
| 60 | if (inString != null) {
| |
| 61 | // trim off any whitespace: | |
| 62 | inString = trim(inString); | |
| 63 | // convert to an int and map to the screen height: | |
| 64 | analogPin = float(inString); | |
| 65 | println(analogPin); | |
| 66 | analogPin = map(analogPin, 0, 1023, 0, 255); | |
| 67 | } | |
| 68 | } |