Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- IntList M,R,G,H;
- import processing.serial.*;
- int Width=800;
- Serial myPort;
- int Lenght=400;
- void setup(){
- String portName = Serial.list()[0];
- myPort = new Serial(this, portName, 9600);
- size(800, 400);
- M = new IntList();
- R = new IntList();
- G = new IntList();
- H = new IntList();
- for (int i=0; i<200; i++) {
- M.append(1);
- R.append(1);
- G.append(1);
- H.append(1);
- }
- fill(255);
- rectMode(CORNERS);
- }
- void print_please(){
- background(0);
- graph();
- }
- void draw(){
- if (myPort.available()>=4){
- int x = myPort.read();
- int y = myPort.read();
- int z = myPort.read();
- int s = myPort.read();
- M.remove(0);
- //M.append(M.get(M.size()-1)+(int)random(-3,3));
- M.append(x);
- R.remove(0);
- R.append(y);
- G.remove(0);
- G.append(z);
- H.remove(0);
- H.append(s);
- print_please();}
- }
- void graph(){
- for (int i=0; i<200; i++){
- fill(255,0,0);
- rect((i*3)+20, 400-M.get(i), ((i+1)*3)+20, 400-M.get(i)+5);
- fill(0,255,0);
- rect((i*3)+20, 400-R.get(i), ((i+1)*3)+20, 400-R.get(i)+5);
- fill(0,0,255);
- rect((i*3)+20, 400-G.get(i), ((i+1)*3)+20, 400-G.get(i)+5);
- fill(125,125,125);
- rect((i*3)+20, 400-H.get(i), ((i+1)*3)+20, 400-H.get(i)+5);
- }
- }
- void setup() {
- pinMode(A0, INPUT);
- pinMode(A1, INPUT);
- pinMode(A2, INPUT);
- pinMode(A3, INPUT);
- Serial.begin(9600);
- }
- void loop() {
- int x,y,z,s;
- x = analogRead(A0);
- y = analogRead(A1);
- z = analogRead(A2);
- s = analogRead(A3);
- Serial.write(x/4);
- Serial.write(y/4);
- Serial.write(z/4);
- Serial.write(s/4);
- delay(50);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement