I require some help with creating a program. (Resistors)

edited February 2018 in Library Questions

The criteria below should be met but I am seemily very much out of my depth. Any help to point me in the right direction would be much appreciated.

Thanks in advance.

A program that allows the user to enter at least 10 resistor sizes by entering the colour codes as letter combinations separated by commas or coloured buttons that can be pressed in order to select the band colours.

After entering the last resistor the operator will enter Done/done to indicate they’ve finished and are ready to enter supply voltage, output voltage and range.

The program must calculate the 2 resistor voltage divider and produce a text based matrix highlighting all the good choices considering the voltage drop required. The output will be formatted in a matrix and as a list of the top 5 choices.

I hope this makes some sense to people

Tagged:

Answers

  • thank you, im not entirely surely what this is? will this run if i put it straight into processing?

  • edited February 2018

    Yes, placing both "Test.pde" & "Inputs.java" folder in a folder called "Test/", they'll run under Processing's IDE (PDE). :-\"

    But notice that "Test.pde" is merely a sample on how to use "Inputs.java".
    You're gonna need to replace "Test.pde" by your own code of course. #:-S

    As you might be imagining by now, "Inputs.java" is a library which opens a dialog and accepts user input; then returns it for a specific datatype depending on the method invoked for it. :-$

  • Any help to point me in the right direction would be much appreciated.

    Ok, some thoughts:

    A program that allows the user to enter at least 10 resistor sizes by entering the colour codes as letter combinations separated by commas or coloured buttons that can be pressed in order to select the band colours.

    Does "or" mean you must implement both interfaces, or you may implement either interface?

    Do you have a sample of what the 10 resistor sizes are? Why don't you share them here as color codes.

    After entering the last resistor the operator will enter Done/done to indicate they’ve finished and are ready to enter supply voltage, output voltage and range.

    Is that interface a DONE button, or typing the word "done", or must it support both options?

    The program must calculate the 2 resistor voltage divider

    Can you briefly explain what this means?

    and produce a text based matrix

    Does that mean something that looks like this?

    highlighting all the good choices considering the voltage drop required.

    Does "highlighting" mean surrounding an option in * marks?

    The output will be formatted in a matrix and as a list of the top 5 choices.

    This is definitely something complex enough that you want to break it down into a lot of little parts, then solve each part separately.

  • edited February 2018

    i have made some progress on this yesterday afternoon which is below.

    the colour code is representative of the colours on the resistor itself. e.g black = 0, white = 9 and everything in between in order. if brown, red, orange were pressed in that order then 123 ohms would be the value of the resistor.

    a done button would be fine

    the voltage divider rule VR=Vs*(R1/(R1+R2)) basically, it would provide the 2 most suitable resistors to give the voltage drop required.

    heres what i have so far.

    import controlP5.*;
    
    ControlP5 cp5;
    
    int value=-1;
    int holdvalue[]=new int[3];
    float resistors[]=new float[10];
    
    
    
    void colourbutton(String name, int y, int r, int g, int b) {
      cp5.addButton(name)
        .setPosition(100, y)
        .setSize(50, 40)
        .getCaptionLabel().align(ControlP5.CENTER, ControlP5.CENTER)
        .setColorBackground(color(r, g, b))
        ;
    }
    void Loadbutton(String name, int y) {
      cp5.addBang(name)
        .setPosition(500, y)
        .setSize(40, 40)
        .getCaptionLabel().align(ControlP5.CENTER, ControlP5.CENTER)
        ;
    }
    
    void setup() {
      size(700, 420);
    
      PFont font = createFont("arial", 80);
    
      cp5 = new ControlP5(this);
    
      colourbutton("Black", 10, 0, 0, 0);
      colourbutton("Brown", 50, 80, 48, 8);
      colourbutton("Red", 90, 255, 0, 0);
      colourbutton("Orange", 130, 255, 116, 3);
      colourbutton("Yellow", 170, 255, 25, 3);
      colourbutton("Green", 210, 0, 255, 0);
      colourbutton("Blue", 250, 0, 0, 255);
      colourbutton("Violet", 290, 137, 38, 188);
      colourbutton("Grey", 330, 170, 170, 170);
      colourbutton("White", 370, 255, 255, 255);
      ;
    
      for (int lb=0; lb<10; lb++) {
        Loadbutton("Load"+(lb+1), (lb*40)+10);
      }
    }
    
    
    int p=0;
    void draw() {
      if (value!=-1) {
        holdvalue[p]=value;
        text(holdvalue[0], 200, 150);
        text(holdvalue[1], 200, 200);
        text(holdvalue[2], 200, 250);
        p=p+1;
        if (p>3) p=0;
        value=-1;
      }
    
      for (int x=0; x<10; x++) {
        if (resistors[x]!=0) {
          text(resistors[x], 600, (20*x)+100);
        }
      }
    }
    
    
    void Black() {
      value=0;
    }
    void Brown() {
      value=1;
    }
    void Red() {
      value=2;
    }
    void Orange() {
      value=3;
    }
    void Yellow() {
      value=4;
    }
    void Green() {
      value=5;
    }
    void Blue() {
      value=6;
    }
    void Violet() {
      value=7;
    }
    void Grey() {
      value=8;
    }
    void White() {
      value=9;
    }
    
    void Load(int pos) {
      resistors[pos]=(holdvalue[100])+holdvalue[10]+holdvalue[0];
      p=0;
      holdvalue[0]=0;
      holdvalue[1]=0;
    }
    void Load1() {
      Load(0);
    }
    void Load2() {
      Load(1);
    }
    void Load3() {
      Load(2);
    }
    void Load4() {
      Load(3);
    }
    void Load5() {
      Load(4);
    }
    void Load6() {
      Load(5);
    }
    void Load7() {
      Load(6);
    }
    void Load8() {
      Load(7);
    }
    void Load9() {
      Load(8);
    }
    void Load10() {
      Load(9);
    }
    

    Many Thanks

  • Go back and edit your post

    Format your code

  • so,,,here's the latest progress. i just have the voltage divider left to do.

    import controlP5.*;
    
    ControlP5 cp5;
    
    int value=-1;
    int holdvalue[]=new int[5];
    float resistors[]=new float[10];
    String textValue = "";
    
    Textlabel Resistor;
    
    void ButtonColor(String name, int y, int r, int g, int b ) {
      cp5.addButton(name)
        .setPosition(100, y)
        .setSize(50, 40)
        .setColorBackground(color(r, g, b))
        .getCaptionLabel().align(ControlP5.CENTER, ControlP5.CENTER)
        ;
    }
    void Loadbutton(String name, int y) {
      cp5.addBang(name)
        .setPosition(450, y)
        .setSize(40, 40)
        .getCaptionLabel().align(ControlP5.CENTER, ControlP5.CENTER)
        ;
    }
    
    
    
    void setup() {
      size(900, 420);
    
    
    
      PFont font = createFont("arial", 20);
      textSize(20);
    
      cp5 = new ControlP5(this);
    
      ButtonColor("Black", 10, 0, 0, 0);
      ButtonColor("Brown", 50, 80, 48, 8);
      ButtonColor("Red", 90, 255, 0, 0);
      ButtonColor("Orange", 130, 255, 116, 3);
      ButtonColor("Yellow", 170, 255, 255, 3);
      ButtonColor("Green", 210, 0, 255, 0);
      ButtonColor("Blue", 250, 0, 0, 255);
      ButtonColor("Violet", 290, 137, 38, 188);
      ButtonColor("Grey", 330, 170, 170, 170);
      ButtonColor("White", 370, 255, 255, 255);
      ;
    
      Resistor=cp5.addLabel("Res Value") 
        .setPosition(220, 50)
        .setSize(200, 40)
        .setFont(font)
        .setColor(color(255, 0, 0))
        ;
    
      cp5.addBang("Clear")
        .setPosition(220, 80)
        .setSize(200, 40)
        .setLabel("Clear")
        .getCaptionLabel().align(ControlP5.CENTER, ControlP5.CENTER)
        ;
    
      for (int lb=0; lb<10; lb++) {
        Loadbutton("Load"+(lb+1), (lb*40)+10);
      }
    
    
      cp5.addTextfield("Input Voltage")
        .setPosition(220, 140)
        .setSize(200, 40)
        .setFont(font)
        .setFocus(true)
        .setColor(color(255, 0, 0))
        ;
    
      cp5.addTextfield("Output Voltage")
        .setPosition(220, 220)
        .setSize(200, 40)
        .setFont(font)
        .setFocus(true)
        .setColor(color(255, 0, 0))
        ;
    }
    int p=0;
    void draw() {
      background(0);
      if (value!=-1) {
        holdvalue[p]=value;
        Resistor.setValue(str(holdvalue[0])+"  "+str(holdvalue[1])+"  "+str(holdvalue[2]));     //+"  "+str(holdvalue[3]));     //*pow(10,holdvalue[3])
        p=p+1;
        if (p>4) Clear();
        value=-1;
      }
    
      for (int x=0; x<10; x++) {
        if (resistors[x]!=0) {
          text(resistors[x], 500, (40*x)+40);
        }
      }
    }
    
    void Clear() {
      p=0;
      holdvalue[0]=0;
      holdvalue[1]=0;
      holdvalue[2]=0;
      holdvalue[3]=0;
      Resistor.setValue("");
    }
    
    
    void Black() {
      value=0;
    }
    void Brown() {
      value=1;
    }
    void Red() {
      value=2;
    }
    void Orange() {
      value=3;
    }
    void Yellow() {
      value=4;
    }
    void Green() {
      value=5;
    }
    void Blue() {
      value=6;
    }
    void Violet() {
      value=7;
    }
    void Grey() {
      value=8;
    }
    void White() {
      value=9;
    }
    
    void Load(int pos) {
      resistors[pos]=((holdvalue[0]*100)+(holdvalue[1]*10)+holdvalue[2])*pow(10, holdvalue[3]);
      Clear();
    }
    
    void Load1() {
      Load(0);
    }
    void Load2() {
      Load(1);
    }
    void Load3() {
      Load(2);
    }
    void Load4() {
      Load(3);
    }
    void Load5() {
      Load(4);
    }
    void Load6() {
      Load(5);
    }
    void Load7() {
      Load(6);
    }
    void Load8() {
      Load(7);
    }
    void Load9() {
      Load(8);
    }
    void Load10() {
      Load(9);
    }
    
  • I don't feel this is very userfriendly.

    A program that allows the user to enter at least 10 resistor sizes by entering the colour codes as ... coloured buttons that can be pressed in order to select the band colours

    I'd expect that the program gives out a text "Enter three colors for resistor 1", then "Enter three colors for resistor 2" and so forth.

    No buttons Load 1, Load 2 etc.

    Next to each resistor slot the colors should also appear plus resistor size.

    After entering the last resistor the operator will enter Done/done to indicate they’ve finished and are ready to enter supply voltage, output voltage and range.

    I would expect a new screen without the resistors but with the fields for enter supply voltage, output voltage and range.

    ...and produce a text based matrix highlighting all the good choices

    A 3rd screen for the matrix.

    Best, Chrisir ;-)

Sign In or Register to comment.