adjusting draw length of a square wave

edited November 2013 in Arduino

Hello all, hope I put this in the correct section. I'm very green to coding processing and arduino.

I have found and modified some code I found that suits my needs of taking a digital 1, 0 and plotting it as a square wave.

The problem I am having is when screen is at size 400, 400 the square wave timing is ok but when I change screen size to 1000, 400 the scroll slows resulting in the wave runs together giving what looks like a strait line at 0 and at 1.


import processing.serial.*;
import cc.arduino.*;

Arduino arduino;


int [] eecgraph;
int [] icmgraph;
int etapa = 0;
int tA = 0;
int tB = 0;
int tC = 0;
 
int pipeec = 38;
int pipicm = 39;
 
void traceBooleanSignal (int [] signal, int ypos, int amplitude, color c1) {
  stroke(c1);
  for (int i = 1; i < width; i++) {
    line(i, ypos+amplitude-signal[i]*amplitude, i, ypos+amplitude-signal[i-1]*amplitude);
  }
}
 
void updateBooleanSignal (int [] signal) {
  for (int i = 1; i < width; i++) {
    signal[i-1] = signal[i];
  }
}
 
void setup()
{
  size(1000, 400);
  
  arduino = new Arduino(this, "COM5", 57600);
  arduino.pinMode(pipeec, Arduino.INPUT);
  arduino.pinMode(pipicm, Arduino.INPUT);
  
  eecgraph = new int[width];
  for (int i = 1; i < width; i++) {
    eecgraph[i] = 0;
  } 
  icmgraph = new int[width];
  for (int i = 1; i < width; i++) {
    icmgraph[i] = 0;
  }
}
 
void draw ()
{
  background(0);
 
  if (arduino.digitalRead(pipeec) == Arduino.HIGH) {
    eecgraph[width-1] = 1;
  }
  else {
    eecgraph[width-1] = 0;
  }
  
    if (arduino.digitalRead(pipicm) == Arduino.HIGH) {
    icmgraph[width-1] = 1;
  }
  else {
    icmgraph[width-1] = 0;
  }
 
  
 
  updateBooleanSignal(eecgraph);
  traceBooleanSignal(eecgraph, 150, 40, color(255, 0, 0));
  updateBooleanSignal(icmgraph);
  traceBooleanSignal(icmgraph, 250, 40, color(0, 255, 0));
}

How would one go about changing the timing so the on and off time is wider? can it be done through an INT so both graphs can be adjusted to the same value at the same time?

Thanks, Dom

Answers

Sign In or Register to comment.