simple metro

For students in the 11217 introduction to construction class;

Here is an example of a simple metronome counter which moves a line up and down a sketch window over a period of time.  You should be able to follow the comments included to see how you might plug your sensors and motors into this sketch to easily arrange for your motors to move a) automatically left/right over a period of time and b) increasing in intensity based on a reading from your slider/light/proximity sensors.

For the purposes of instruction and demonstration, i've connected the line movement to simple mouse input - move the mouse left/right to influence up/down motion - so you can see how your sensors might influence pre-programmed movement.

Paste this sketch into a new processing window to test it out;
...

 
float speed = 5.0; // you should connect this to your slider (eg speed = slider), but only after you map the slider to a reasonable range
// eg the slider range should be limited from 0-1000 to a reasonable range such as 1-25
 
float step = 0.5; // this is the resolution of movement you take each time (you should experiment with values such as 0.1 or 1.0 to see which works best)
float direction = 1.0; // this determines whether the value is increasing or decreasing
 
float value = 0.0; // you should connect this to your motor (eg sp.setPosition(0,value))
float drawLine; // this just draws the value to screen as a horizontal line
 
void setup() {
frameRate(24)// change this to a lower amount to slow things down
size(200,250);
}
 
void draw() {
background(255); //clear what was drawn the frame before
speed = map(mouseX,0,width,0.1,25.0)// change this to allow your slider to control the line!
if (value > 232.0) {
direction = direction * -1.0; //move back down when you reach the top
}
if (value < -22.9) {
direction = direction * -1.0; //move back up when you reach the bottom
}
value = value+(step*speed*direction);
println("value is " + value); // tell me where you are
drawLine = map(value,-22.9,232.0,0,height); // map the value to the range available in your window
line(0,drawLine,width,drawLine); // draw a line
}
 

Give it a try, it should help in automating your systems, note also that this will mainly work with the simple motors we've given you (that cannot move through more than 360 degrees), not continuous movement motors.

[UPDATE] this is the same sketch, embedded using the superb combination of hascanvas + processingjs. Move your mouse left and right over the sketch window to modify the metronome speed of the line.

Related Posts

architecture com dab data float gallery google information interface j line pixeltag processing   39

Add Your Comments

Required
Required
Tips

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <ol> <ul> <li> <strong>

Your email is never published nor shared.

Ready?