Generate a single file p5.js sketch on a 400x400 canvas that simulates an LED electrical circuit. The circuit has had the following elements connected in series.

  1. A battery on the left with the positive end at the top.
  2. A wire from the battery to a switch
  3. An on/off switch at the top connecting the battery to a 220K ohm resistor with a wire.
  4. The 220-ohm resistor on the top right with a wire to an LED.
  5. An LED and a light bulb on the bottom right that is red when the circuit is on and black when the circuit is open.
  6. A wire connecting the bottom of the LED to the negative side of the battery.
Place a button at the bottom of the canvas that will toggle the switch on and off.
Draw symbols for a battery, switch, resistor and LED.
Use the following function to draw the wires:

// Function for drawing an animated wire
function drawAnimatedWire(x1, y1, x2, y2, speed1, state) {
    if (state) {
        let distance = dist(x1, y1, x2, y2);
        let circlePos = map((millis() * speed1) % distance, 0, distance, 0, 1);

        // lerp generates the percent between two values
        let x = lerp(x1, x2, circlePos);
        let y = lerp(y1, y2, circlePos);

        stroke(0);
        strokeWeight(lineWidth)
        line(x1, y1, x2, y2); // Draw the wire

        fill(255, 0, 0);
        noStroke();
        circle(x, y, 10); // Draw the moving circle (electron)
    } else {
        stroke(0);
        strokeWeight(lineWidth)
        line(x1, y1, x2, y2); // Draw the wire
    }
}