Created
June 6, 2013 00:32
-
-
Save tmathmeyer/5718454 to your computer and use it in GitHub Desktop.
arduino oscope
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import processing.serial.*; | |
Serial port; // Create object from Serial class | |
int val; // Data received from the serial port | |
int[] values; | |
void setup() | |
{ | |
size(640, 480); | |
// Open the port that the board is connected to and use the same speed (9600 bps) | |
port = new Serial(this, Serial.list()[0], 9600); | |
values = new int[width]; | |
smooth(); | |
} | |
int getY(int val) { | |
return (int)(val / 1023.0f * height) - 1; | |
} | |
void draw() | |
{ | |
while (port.available() >= 3) { | |
if (port.read() == 0xff) { | |
val = (port.read() << 8) | (port.read()); | |
} | |
} | |
for (int i=0; i<width-1; i++) | |
values[i] = values[i+1]; | |
values[width-1] = val; | |
background(0); | |
stroke(255); | |
for (int x=1; x<width; x++) { | |
line(width-x, height-1-getY(values[x-1]), | |
width-1-x, height-1-getY(values[x])); | |
} | |
} | |
/* | |
// The Arduino code. | |
#define ANALOG_IN 0 | |
void setup() { | |
Serial.begin(9600); | |
} | |
void loop() { | |
int val = analogRead(ANALOG_IN); | |
Serial.print( 0xff, BYTE); | |
Serial.print( (val >> 8) & 0xff, BYTE); | |
Serial.print( val & 0xff, BYTE); | |
} | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Using the 'print' method wastes a lot of time.
void setup() {
// initialize serial:
Serial.begin(115200);
Serial.println("start");
}
void loop() {
byte a = analogRead(A1)/2;//shift to the right
Serial.write(a);
//A byte stores an 8-bit unsigned number, from 0 to 255 by shifting only from the lsb,
// for analog audio, you get a bit of a boost from the input (good for signals that are +- 1v p-p).
You might want to purchase an audio shield that gives you a proper connector...here:
// http://tinyurl.com/AudioShield
}