// Creating multibit register display code // Class Register8 is a class to store and display an 8-bit register Register8 myRegister; int j; // Standard issue i void setup() { size(256,200); background(0,164,64); myRegister = new Register8(); myRegister.xpos = 0; myRegister.ypos = 0; // myRegister.value = 15; // myRegister.display(); } void draw() { // myRegister.value = j; // println("myRegister.value = " + myRegister.value); myRegister.display(mouseX); } void mousePressed() { redraw(); } class Register8 { float xpos; // Upper left X position of register float ypos; // Upper left Y position of register color oncolor; // Color of lit bit indicator color offcolor; // Color of unlit bit indicator color outline; // Color of rectangle and indicator outlines color bgcolor; // Color of rectangle background color bitcolor; // Color selected for this bit float bitxpos; // Xpos of particular bit int value; // Value of this 8-bit register int i; //Local i Register8() { // Register 8 Constructor [DEPRECATED] I like using the class.vars xpos = 0; ypos = 0; oncolor = color(0,255,0); offcolor = color(64,92,64); outline = color(0,0,0); bgcolor = color(64,64,64); bitcolor = 0; bitxpos = 0; value = 0; i = 0; } void display( int t_value ) { value = t_value; stroke(outline); fill(bgcolor); rect(xpos,ypos,160,20); ellipseMode(CORNER); for ( i = 0; i < 8; i++ ) { if ( (value & (1 << i)) != 0 ) { // println (" value != 0"); bitcolor = oncolor; } else { // println (" value = 0"); bitcolor = offcolor; } fill(bitcolor); bitxpos = (xpos + 160) - ((i+1) * 20); ellipse(bitxpos, ypos, 20, 20); } } }