Avatar for ImBrownie77

ImBrownie77

Member since May 2018 • Last active May 2018
  • 1 conversations
  • 3 comments

Most recent activity

  • in Electronics
    Avatar for ImBrownie77

    Thank you Gordon for your help, this worked.

  • in Electronics
    Avatar for ImBrownie77

    Thanks for your reply Gordon, I’ll give the USB.setConsole(1) a try. This has been driving me nuts!!

  • in Electronics
    Avatar for ImBrownie77

    Hello everyone,

    I’m looking for some help on my project. I had the idea of having switches in my gearstick and then a seven segment display show what gear I was in.

    So I have a Pico with switches on B3, B4, B5, B7 and A8, they have a common positive 3.3 from the pin next to B3.

    Gear - Active Switches
    1 = B4 & A8
    2 =B4 & B7
    3 = A8
    4 = B7
    5 = B5 & A8
    6 = B5 & B7
    R = B3, B4 & A8

    I then have the following pins linked to a single seven segment display:
    A5 (a), A6 (b), A7 (c), B10 (d), B13 (e), B14 (f) and B15 (g).

    The code I have below works when connected to my MacBook but when I disconnect it and then power it back up, it hangs on some of the switches. I can go through all the ‘gears’ and then it hangs on 6 or reverse.

    I was hoping you kind people would help me out and let me know what I’m doing wrong.

    function None() {
      digitalWrite(A5, 0);
      digitalWrite(A6, 0);
      digitalWrite(A7, 0);
      digitalWrite(B10, 0);
      digitalWrite(B13, 0);
      digitalWrite(B14, 0);
      digitalWrite(B15, 1);
    }
    function One() {
      digitalWrite(A5, 0);
      digitalWrite(A6, 1);
      digitalWrite(A7, 1);
      digitalWrite(B10, 0);
      digitalWrite(B13, 0);
      digitalWrite(B14, 0);
      digitalWrite(B15, 0);
    }
    function Two() {
      digitalWrite(A5, 1);
      digitalWrite(A6, 1);
      digitalWrite(A7, 0);
      digitalWrite(B10, 1);
      digitalWrite(B13, 1);
      digitalWrite(B14, 0);
      digitalWrite(B15, 1);
    }
    function Three() {
      digitalWrite(A5, 1);
      digitalWrite(A6, 1);
      digitalWrite(A7, 1);
      digitalWrite(B10, 1);
      digitalWrite(B13, 0);
      digitalWrite(B14, 0);
      digitalWrite(B15, 1);
    }
    function Four() {
      digitalWrite(A5, 0);
      digitalWrite(A6, 1);
      digitalWrite(A7, 1);
      digitalWrite(B10, 0);
      digitalWrite(B13, 0);
      digitalWrite(B14, 1);
      digitalWrite(B15, 1);
    }
    function Five() {
      digitalWrite(A5, 1);
      digitalWrite(A6, 0);
      digitalWrite(A7, 1);
      digitalWrite(B10, 1);
      digitalWrite(B13, 0);
      digitalWrite(B14, 1);
      digitalWrite(B15, 1);
    }
    function Six() {
      digitalWrite(A5, 1);
      digitalWrite(A6, 0);
      digitalWrite(A7, 1);
      digitalWrite(B10, 1);
      digitalWrite(B13, 1);
      digitalWrite(B14, 1);
      digitalWrite(B15, 1);
    }
    function Reverse() {
      digitalWrite(A5, 0);
      digitalWrite(A6, 0);
      digitalWrite(A7, 0);
      digitalWrite(B10, 0);
      digitalWrite(B13, 1);
      digitalWrite(B14, 0);
      digitalWrite(B15, 1);
    }
    function onInit(){
      
      // Set the pins for input
      pinMode(A8, "input_pulldown");
      pinMode(B7, "input_pulldown");
      pinMode(B5, "input_pulldown");
      pinMode(B4, "input_pulldown");
      pinMode(B3, "input_pulldown");
      
      // Test the display by going through the numbers
      None();
      var t=getTime()+1;while(getTime()<t);
      digitalWrite(B15, 1);
      t=getTime()+0.1;while(getTime()<t);
      digitalWrite(B14, 1);
      t=getTime()+0.1;while(getTime()<t);
      digitalWrite(A5, 1);
      t=getTime()+0.1;while(getTime()<t);
      digitalWrite(A6, 1);
      t=getTime()+0.1;while(getTime()<t);
      digitalWrite(A7, 1);
      t=getTime()+0.1;while(getTime()<t);
      digitalWrite(B10, 1);
      t=getTime()+0.1;while(getTime()<t);
      digitalWrite(B13, 1);
      
      t=getTime()+0.1;while(getTime()<t);
      digitalWrite(B15, 0);
      t=getTime()+0.1;while(getTime()<t);
      digitalWrite(B14, 0);
      t=getTime()+0.1;while(getTime()<t);
      digitalWrite(A5, 0);
      t=getTime()+0.1;while(getTime()<t);
      digitalWrite(A6, 0);
      t=getTime()+0.1;while(getTime()<t);
      digitalWrite(A7, 0);
      t=getTime()+0.1;while(getTime()<t);
      digitalWrite(B10, 0);
      t=getTime()+0.1;while(getTime()<t);
      digitalWrite(B13, 0);
      t=getTime()+0.1;while(getTime()<t);
      
      One();
      t=getTime()+0.25;while(getTime()<t);
      Two();
      t=getTime()+0.25;while(getTime()<t);
      Three();
      t=getTime()+0.25;while(getTime()<t);
      Four();
      t=getTime()+0.25;while(getTime()<t);
      Five();
      t=getTime()+0.25;while(getTime()<t);
      Six();
      t=getTime()+0.25;while(getTime()<t);
      Reverse();
      t=getTime()+0.25;while(getTime()<t);
      None();
    }
    
    
    setWatch(function () {if (digitalRead(A8)) {
        if (digitalRead(B5)) {
          print('5');
          Five();
        }
        if (digitalRead(B4) && digitalRead(B3)) {
          print('R');
          Reverse();
        } else if (digitalRead(B4) && digitalRead(B3) == false) {
          print('1');
          One();
        }
        if (digitalRead(B3)
          == false && digitalRead(B4)
          == false && digitalRead(B5)
          == false) {
          print('3');
          Three();
        }
      } else {
        print('Npoe');
        None();
      }}, A8, { repeat:true, debounce:10 });
    
    
    setWatch(function () {if (digitalRead(B7)) {
        if (digitalRead(B4)) {
          print('2');
          Two();
        } else if (digitalRead(B5)) {
          print('6');
          Six();
        } else {
          print('4');
          Four();
        }
      } else {
        print('Npoe');
        None();
      }}, B7, { repeat:true, debounce:10 });
    
Actions