Post Format

★ 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.Give this sketch a try…
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 using processingjs. Move your mouse left and right over the sketch window to modify the metronome speed of the line.

float speed = 5.0;float step = 0.5;float direction = 1.0;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 linevoid setup() {frameRate(24);  // change this to a lower amount to slow things downsize(200,250);}void draw() {background(255); //clear what was drawn the frame beforespeed = 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);drawLine = map(value,-22.9,232.0,0,height); // map the value to the range available in your windowline(0,drawLine,width,drawLine); // draw a line}