I want to modify my resistor code to do something cool

int bandValue=0;//defines bandvalue
int countClicks=0;//defines countclicks
int firstBand=0;//defines firstband
int secondBand=0;//defines secondband
int thirdBand=0;//defines thirdband
int resistor_value=0;//defines resistor value)
void setup() {
size(500, 500);//sets screen size
}

void draw() {
background(275);//sets background colour to grey
for (int i=0; i<=450; i+=50) {//draws the 10 boxes to the left hand side
switch(i)
{
case 0:
fill(0);//makes 1st box black
break;

case 50:
  fill(#7E4417);//makes 2nd box brown
  break;

case 100:
  fill(#B40923);//makes 3rd box red
  break;
case 150:
  fill(#F25B02);//makes 4th box orange
  break;
case 200:
  fill(#FFEB03);//makes 5th box yellow
  break;
case 250:
  fill(#A1CE0F);//makes 6th box green 
  break;
case 300:
  fill(#0F9CCE);//makes 7th box blue
  break;
case 350:
  fill(#6111A7);//makes 8th box purple
  break;
case 400:
  fill(#938F8B);//makes 9th box silver
  break;
case 450:
  fill(#FFFEFA);//makes 10th box white
  break;
}



rect(0, i, 50, 50);//draws a rectangle

}
textSize(50);//sets text size
text(resistor_value+“Ω”, width/2, height/2);//displays text
}

void mousePressed() {
countClicks++;//counts number of clicks

println(“Mouse clicks=”, countClicks);//displays mouse Click
println(mouseX, mouseY);
if ((mouseX>0&&mouseX<50)&&(mouseY>0&&mouseY<50)) {//sets the condition
bandValue=0;//sets bandvalue to 0
println(“BLACK”, bandValue);//displays bandvalue and black
}
if ((mouseX>0&&mouseX<50)&&(mouseY>50&&mouseY<100)) {//sets the condition
bandValue=1;//sets bandvalue to 1
println(“BROWN”, bandValue);//displays bandvalue and brown
}
if ((mouseX>0&&mouseX<50)&&(mouseY>100&&mouseY<150)) {//sets the condition
bandValue=2;//sets bandvalue to 2
println(“RED”, bandValue);//displays bandvalue and red
}
if ((mouseX>0&&mouseX<50)&&(mouseY>150&&mouseY<200)) {//sets the condition
bandValue=3;//sets bandvalue to 3
println(“ORANGE”, bandValue);//displays bandvalue and orange
}
if ((mouseX>0&&mouseX<50)&&(mouseY>200&&mouseY<250)) {//sets the condition
bandValue=4;//sets bandvalue to 4
println(“YELLOW”, bandValue);//displays bandvalue and yellow
}
if ((mouseX>0&&mouseX<50)&&(mouseY>250&&mouseY<300)) {//sets the condition
bandValue=5;//sets bandvalue to 5
println(“GREEN”, bandValue);//displays bandvalue and black
}
if ((mouseX>0&&mouseX<50)&&(mouseY>300&&mouseY<350)) {//sets the condition
bandValue=6;//sets bandvalue to 6
println(“BLUE”, bandValue);//displays bandvalue and blue
}
if ((mouseX>0&&mouseX<50)&&(mouseY>350&&mouseY<400)) {//sets the condition
bandValue=7;//sets bandvalue to 7
println(“VIOLET”, bandValue);//displays bandvalue and violet
}
if ((mouseX>0&&mouseX<50)&&(mouseY>400&&mouseY<450)) {//sets the condition
bandValue=8;//sets bandvalue to 8
println(“SILVER”, bandValue);//displays bandvalue and silver
}
if ((mouseX>0&&mouseX<50)&&(mouseY>450&&mouseY<500)) {//sets the condition
bandValue=9;//sets bandvalue to 9
println(“WHITE”, bandValue);//displays bandvalue and white
}

//if(countClicks==3){//resets number of clicks
// countClicks=0;
//}

switch(countClicks) {
case 1:
firstBand=bandValue;
println(“First band value is=”, firstBand);//displays first bandvalue
break;

case 2:
secondBand=bandValue;
println(“Second band value is=”, secondBand);//displays second bandvalue
break;

case 3:
thirdBand=bandValue;
println(“Third band value is=”, thirdBand);//displays third bandvalue

countClicks=0;
println("Calculate Resistor Value");//displays calculate resistor value

resistor_value=((firstBand*10)+secondBand)*int(pow(10, thirdBand));//calculates resistor value
println("Resistor Value is", resistor_value);//displays resistor value

}
}

Oh, great idea! And it also can be useful for us electronic makers.
Let’s do it together!
Here’s my first contribution. A list with the most common resistor values.
Can you draw the resistor with colored rings as natural-looking as possible?

String[] resistor_values = {
  "1.0", "1.1", "1.2", "1.3", "1.5", "1.6", "1.8", "2.0", "2.2", "2.4", "2.7", "3.0", "3.3", "3.6", " 3.9", "4.3", "4.7", "5.1", "5.6", "6.2", "6.8", "7.5", "8.2", "9.1", 
  "10", "11", "12", "13", "15", "16", "18", "20", "22", "24", "27", "30", "33", "36", "39", "43", "47", "51", "56", "62", "68", "75", "82", "91", 
  "100", "110", "120", "130", "150", "160", "180", "200", "220", "240", "270", "300", "330", "360", "390", "430", "470", "510", "560", "620", "680", "750", "820", "910", 
  "1.0K", "1.1K", "1.2K", "1.3K", "1.5K", "1.6K", "1.8K", "2.0K", "2.2K", "2.4K", "2.7K", "3.0K", "3.3K", "3.6K", " 3.9K", "4.3K", "4.7K", "5.1K", "5.6K", "6.2K", "6.8K", "7.5K", "8.2K", "9.1K", 
  "10K", "11K", "12K", "13K", "15K", "16K", "18K", "20K", "22K", "24K", "27K", "30K", "33K", "36K", "39K", "43K", "47K", "51K", "56K", "62K", "68K", "75K", "82K", "91K", 
  "100K", "110K", "120K", "130K", "150K", "160K", "180K", "200K", "220K", "240K", "270K", "300K", "330K", "360K", "390K", "430K", "470K", "510K", "560K", "620K", "680K", "750K", "820K", "910K", 
  "1.0M", "1.1M", "1.2M", "1.3M", "1.5M", "1.6M", "1.8M", "2.0M", "2.2M", "2.4M", "2.7M", "3.0M", "3.3M", "3.6M", " 3.9M", "4.3M", "4.7M", "5.1M", "5.6M", "6.2M", "6.8M", "7.5M", "8.2M", "9.1M"
}; 

float loc;
int index;

void setup() {
  size(600, 300);
  println(resistor_values.length);
  loc = 15;
  textSize(28);
  textAlign(CENTER);
  drawSlider();
}

void draw() {
  background(255); 
  fill(0);
  text(resistor_values[index]+" Ω", width/2, 3*height/4);
  drawSlider();
}

void drawSlider() {
  push();
  noStroke();
  index = int(map(loc, 15, width-15, 0, 167));
  fill(255);
  rect(0, height-30, width, 30); 
  fill(200, 200, 255);
  rect(10, height-15, width-20, 5); 
  fill(150, 150, 255);
  ellipse(loc, height-13, 15, 15);
  pop();
}    

void mouseDragged() {
  loc = mouseX;
  if (loc < 15) loc = 15;
  if (loc > width-15) loc = width-15;
}

Ok thanks will try it

hi id like it to be included in my program and not separated.

dont worry its fine thanks for your help

If you have some difficulties or want an idea, feel free to post it here. :smiley:

hi plz could u comment the code so I can understand the process