Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import processing.serial.*;
- Serial myPort;
- int windowWidth = 1280;
- int windowHeight = 700;
- int upperValue = 700;
- int[] valueArray = new int[windowWidth];
- void setup() {
- size(1280, 700);
- println(Serial.list());
- myPort = new Serial(this, Serial.list()[2], 9600);
- myPort.bufferUntil('\n');
- }
- void draw() {
- background(0);
- if (valueArray != null) {
- for (int i=0; i<valueArray.length; i++) {
- stroke(127, 34, 255);
- line(i, height, i, height - valueArray[i]);
- }
- }
- textSize(10);
- for (int i=0; i<height; i++) {
- if (i % (50) == 0) {
- text(int((map(i, 0, height, upperValue, 0))) + " W", 10, i);
- stroke(60);
- line(0, i, width, i);
- }
- }
- }
- void serialEvent(Serial myPort) {
- String inString = myPort.readStringUntil('\n');
- println(inString);
- if (inString != null) {
- if (inString.startsWith("W ")) {
- println("Watt value!");
- String val = inString.substring(2);
- val = trim(val);
- float inByte = float(val);
- inByte = map(inByte, 0, upperValue, 0, height);
- // Add last value to array
- shiftAndAdd(valueArray, int(inByte));
- }
- }
- }
- void shiftAndAdd(int a[], int val) {
- int a_length = a.length;
- System.arraycopy(a, 1, a, 0, a_length-1);
- a[a_length-1] = val;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement