// Bellicose Birds code by Chris Orban float Q = 0; //initial value float I = 0; //initial value float Vcap; float C = 0.375; float Vbatt = 10; // Volts float R = 5; // Ohms float dt = 0.1; boolean battery_is_connected = false; DPGraph graph1 = new DPGraph(); DPGraph graph2 = new DPGraph(); PImage imgConnected; PImage imgDisconnected; void setup() { size(750,500); smooth(); Q = 0; I = 0; graph1.colorFunction = color(255,177,100); //orange graph1.xTitle = "time"; graph2.colorFunction = color(0,191,191); //aqua imgDisconnected = loadImage("http://www.physics.ohio-state.edu/~orban/physics1251lab_2016/RCdisconnected.png"); imgConnected = loadImage("http://www.physics.ohio-state.edu/~orban/physics1251lab_2016/RCconnected.png"); } // For people with C and C++ experience, draw() is // very similar to main(), except that draw() // is run over and over again void draw() { if (keyPressed) { if (key == 'c') battery_is_connected = true; if (key == 'd') battery_is_connected = false; } if ( battery_is_connected == true) { I = 0; Vcap = Vbatt; Q = C*Vcap; } else { // battery is not connected I = Vcap/R; Q += -I*dt; Vcap = Q/C; } // This will clear the screen and re-draw it display(); graph1.addPoint(Q); graph1.display(); //println("Q = ",Q); // Uncomment if curious about precise value of Q graph2.addPoint(I); graph2.display(); //println("I = ",I); // Uncomment if curious about precise value of I } // end draw()