Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //arduino
- const int analogInPin0 = A0; // Analog input pin that the potentiometer is attached to
- const int analogInPin1 = A1;
- void setup() {
- Serial.begin(9600);
- }
- void loop() {
- // print the results to the serial monitor:
- Serial.print(analogRead(analogInPin0));
- Serial.print(",");
- Serial.print(analogRead(analogInPin1));
- Serial.print("\n");
- delay(100);
- }
- //processing
- //processing arduino 101
- import processing.serial.*;
- Serial myPort; // The serial port
- float firstValue = 0;
- float secondValue = 0;
- void setup () {
- // set the window size:
- size(1280, 720);
- // List all the available serial ports
- // if using Processing 2.1 or later, use Serial.printArray()
- println(Serial.list());
- // I know that the first port in the serial list on my Mac is always my
- // Arduino, so I open Serial.list()[0].
- // Open whatever port is the one you're using.
- myPort = new Serial(this, Serial.list()[1], 9600);
- // don't generate a serialEvent() unless you get a newline character:
- myPort.bufferUntil('\n');
- }
- void draw () {
- background(255);
- fill(firstValue);
- ellipse(width/2,height/2,secondValue,secondValue);
- }
- void serialEvent (Serial myPort) {
- // get the ASCII string:
- String inString = myPort.readStringUntil('\n');
- if (inString != null) {
- // trim off any whitespace:
- inString = trim(inString);
- // split the string on the commas and convert the resulting substrings
- // into an integer array:
- // println(firstValue + "," + secondValue);
- float[] colors = float(split(inString, ","));
- // if the array has at least three elements, you know you got the whole
- // thing. Put the numbers in the color variables:
- if (colors.length >= 2) {
- // map them to the range 0-255:
- firstValue = map(colors[0], 130, 555, 0, 255);
- secondValue = map(colors[1], 0, 1023, 0, 1000);
- }
- }
- println(firstValue + "," + secondValue);
- }
Add Comment
Please, Sign In to add comment