Results 1 to 9 of 9
  1. #1
    Nintendo Section Moderator PvtRyan's Avatar

    Badge

    Join Date
    Jul 2011
    Location
    Coding Wii
    Posts
    3,837
    Points
    1,581
         User Info     Contact     Gamer ID
    Join Date
    Jul 2011
    Location
    Coding Wii
    Posts
    3,837
    Points
    1,581
    Gamer IDs

    PSN ID: gamer_pvtryan Steam ID: pvtryan_cl Wii Code: PvtRyan

    Contact info:

    Youtube Channel: http://www.youtube.com/xPvtRyanx

    Default Binary Counter LED's controlled by Classic Controller

    So with the parts that I have I decided why not and made a nice binary counter. The diagram below shows how the LED's are alligned in order so you know how to count it.

    Pinoutsleft to right)
    Code:
    /*
    fdf
    */
    
    #include "Wire.h"
    #include "WiiClassic.h"
    const int input1 = 5; //Bit 1 - Number 1
    const int input2 = 4; //Bit 2 - Number 2
    const int input3 = 3; //Bit 3 - Number 4
    const int input4 = 2; //Bit 4 - Number 8
    const int input5 = 12; //Reset LED
    int ON = HIGH;
    int OFF = LOW;
    int ledA = input1;
    int ledB = input2;
    int ledC = input3;
    int ledD = input4;
    int ledE = input5;
    int binaryCount = 0;
    
    WiiClassic wiiClassy = WiiClassic();
    
    void setup() {
      Wire.begin();
      wiiClassy.begin();
      wiiClassy.update();
      pinMode(input1, OUTPUT);
      pinMode(input2, OUTPUT);
      pinMode(input3, OUTPUT);
      pinMode(input4, OUTPUT);
      pinMode(input5, OUTPUT);
    }
    
    void loop() {
      delay(200); // 1ms is enough to not overload the wii Classic, 100ms seems to ease the serial terminal a little
      wiiClassy.update();
      if (wiiClassy.startPressed()) {
        binaryCount += 1;
      }
      if (wiiClassy.selectPressed()) {
        binaryCount -= 1;
      }
      
      if (wiiClassy.homePressed()) {
        binaryCount = 0;
        ledE = ON;
      }
      
      if(binaryCount <= -1 || binaryCount >= 16 )
      {
        binaryCount = 0;
      }
      
      switch( binaryCount )
      {
        case 0:
        ledA = OFF;
        ledB = OFF;
        ledC = OFF;
        ledD = OFF;
              break;
        case 1:
        ledA = ON;
        ledB = OFF;
        ledC = OFF;
        ledD = OFF;
        ledE = OFF;
              break;
        case 2:
        ledA = OFF;
        ledB = ON;
        ledC = OFF;
        ledD = OFF;
              break;
        case 3:
        ledA = ON;
        ledB = ON;
        ledC = OFF;
        ledD = OFF;
              break;
        case 4:
        ledA = OFF;
        ledB = OFF;
        ledC = ON;
        ledD = OFF;
              break;
        case 5:
        ledA = ON;
        ledB = OFF;
        ledC = ON;
        ledD = OFF;
              break;
        case 6:
        ledA = OFF;
        ledB = ON;
        ledC = ON;
        ledD = OFF;
              break;
        case 7:
        ledA = ON;
        ledB = ON;
        ledC = ON;
        ledD = OFF;
              break;
        case 8:
        ledA = OFF;
        ledB = OFF;
        ledC = OFF;
        ledD = ON;
              break;
        case 9:
        ledA = ON;
        ledB = OFF;
        ledC = OFF;
        ledD = ON;
              break;
        case 10:
        ledA = OFF;
        ledB = ON;
        ledC = OFF;
        ledD = ON;
              break;
        case 11:
        ledA = ON;
        ledB = ON;
        ledC = OFF;
        ledD = ON;
              break;
        case 12:
        ledA = OFF;
        ledB = OFF;
        ledC = ON;
        ledD = ON;
              break;
        case 13:
        ledA = ON;
        ledB = OFF;
        ledC = ON;
        ledD = ON;
              break;
        case 14:
        ledA = OFF;
        ledB = ON;
        ledC = ON;
        ledD = ON;
              break;
        case 15:
        ledA = ON;
        ledB = ON;
        ledC = ON;
        ledD = ON;
              break;
      }          
      
      digitalWrite(input1, ledA);
      digitalWrite(input2, ledB);
      digitalWrite(input3, ledC);
      digitalWrite(input4, ledD);
      digitalWrite(input5, ledE);
    }
    [IMG]http://i.imgur.com/LSAhCjk.jpg[IMG]


    The way binary works when the LED is on that is the bit that is currently on, when a single LED is on that bit number is the number that it reads in decimal. If there are more than one LED is on then each bit that is on is added together. Ex. If only bit 8 is on, then 8 is your decimal answer(standard normal number). If 8 and 4 are on, then 8+4=12, the decimal answer is 12.

    2 Not allowed! Not allowed!
    Last edited by PvtRyan; 01-03-2014 at 01:31 PM.


    PS4 Profile:

  2. #2
    Banned

    Badge

    Join Date
    Oct 2013
    Location
    Being Grumpy
    Posts
    1,301
    Points
    285
         User Info     Contact     Gamer ID
    Join Date
    Oct 2013
    Location
    Being Grumpy
    Posts
    1,301
    Points
    285
    Gamer IDs

    Gamertag: CandyCrusher PSN ID: CandyCrusher

    Contact info:

    Youtube Channel: http://www.youtube.com/

    Default

    Quote Originally Posted by PvtRyan View Post
    So with the parts that I have I decided why not and made a nice binary counter. The diagram below shows how the LED's are alligned in order so you know how to count it.

    Pinoutsleft to right)
    Code:
    /*
    Blue LED: Pin 2
    Orange LED: Pin 3
    Red LED: Pin 4
    Yellow LED: Pin 5
    Far Blue LED: Pin 12
    LED Ground's: GND
    
    On Classic Controller:
    Vcc: 3.3V
    GND: GND
    Data: Analog 4(A4)
    Clock: Analog 5(A5) *\
    
    #include "Wire.h"
    #include "WiiClassic.h"
    const int input1 = 5; //Bit 1 - Number 1
    const int input2 = 4; //Bit 2 - Number 2
    const int input3 = 3; //Bit 3 - Number 4
    const int input4 = 2; //Bit 4 - Number 8
    const int input5 = 12; //Reset LED
    int ON = HIGH;
    int OFF = LOW;
    int ledA = input1;
    int ledB = input2;
    int ledC = input3;
    int ledD = input4;
    int ledE = input5;
    int binaryCount = 0;
    
    WiiClassic wiiClassy = WiiClassic();
    
    void setup() {
      Wire.begin();
      wiiClassy.begin();
      wiiClassy.update();
      pinMode(input1, OUTPUT);
      pinMode(input2, OUTPUT);
      pinMode(input3, OUTPUT);
      pinMode(input4, OUTPUT);
      pinMode(input5, OUTPUT);
    }
    
    void loop() {
      delay(200); // 1ms is enough to not overload the wii Classic, 100ms seems to ease the serial terminal a little
      wiiClassy.update();
      if (wiiClassy.startPressed()) {
        binaryCount += 1;
      }
      if (wiiClassy.selectPressed()) {
        binaryCount -= 1;
      }
      
      if (wiiClassy.homePressed()) {
        binaryCount = 0;
        ledE = ON;
      }
      
      if (binaryCount == 0 ) {
        ledA = OFF;
        ledB = OFF;
        ledC = OFF;
        ledD = OFF;
      }
      if (binaryCount == 1 ) {
        ledA = ON;
        ledB = OFF;
        ledC = OFF;
        ledD = OFF;
        ledE = OFF;
      }
      if (binaryCount == 2 ) {
        ledA = OFF;
        ledB = ON;
        ledC = OFF;
        ledD = OFF;
      }
      
      if (binaryCount == 3 ) {
        ledA = ON;
        ledB = ON;
        ledC = OFF;
        ledD = OFF;
      }
      
      if (binaryCount == 4 ) {
        ledA = OFF;
        ledB = OFF;
        ledC = ON;
        ledD = OFF;
      }
      if (binaryCount == 5 ) {
        ledA = ON;
        ledB = OFF;
        ledC = ON;
        ledD = OFF;
      }
    
      if (binaryCount == 6 ) {
        ledA = OFF;
        ledB = ON;
        ledC = ON;
        ledD = OFF;
      }
    
      if (binaryCount == 7 ) {
        ledA = ON;
        ledB = ON;
        ledC = ON;
        ledD = OFF;
      }
    
      if (binaryCount == 8 ) {
        ledA = OFF;
        ledB = OFF;
        ledC = OFF;
        ledD = ON;
      }
    
      if (binaryCount == 9 ) {
        ledA = ON;
        ledB = OFF;
        ledC = OFF;
        ledD = ON;
      }
    
      if (binaryCount == 10 ) {
        ledA = OFF;
        ledB = ON;
        ledC = OFF;
        ledD = ON;
      }
    
      if (binaryCount == 11 ) {
        ledA = ON;
        ledB = ON;
        ledC = OFF;
        ledD = ON;
      }
    
      if (binaryCount == 12 ) {
        ledA = OFF;
        ledB = OFF;
        ledC = ON;
        ledD = ON;
      }
    
      if (binaryCount == 13 ) {
        ledA = ON;
        ledB = OFF;
        ledC = ON;
        ledD = ON;
      }
    
    
      if (binaryCount == 14 ) {
        ledA = OFF;
        ledB = ON;
        ledC = ON;
        ledD = ON;
      }
    
      if (binaryCount == 15 ) {
        ledA = ON;
        ledB = ON;
        ledC = ON;
        ledD = ON;
      }
      
      if(binaryCount <= -1 || binaryCount >= 16 )
      {
        binaryCount = 0;
      }
      
      digitalWrite(input1, ledA);
      digitalWrite(input2, ledB);
      digitalWrite(input3, ledC);
      digitalWrite(input4, ledD);
      digitalWrite(input5, ledE);
    }
    [IMG]http://i.imgur.com/LSAhCjk.jpg[IMG]


    The way binary works when the LED is on that is the bit that is currently on, when a single LED is on that bit number is the number that it reads in decimal. If there are more than one LED is on then each bit that is on is added together. Ex. If only bit 8 is on, then 8 is your decimal answer(standard normal number). If 8 and 4 are on, then 8+4=12, the decimal answer is 12.
    Add a soundboard with piano sounds and you can make a LED controller piano.

    0 Not allowed! Not allowed!

  3. #3

    Retired Prophet
    ToxicJew.'s Avatar
    Join Date
    Mar 2011
    Location
    S̢͎̳̞̲͈̪̳̻ͮͩt̟̳̏ͬ̔&#
    Posts
    7,809
    Points
    7,616
         User Info     Contact     Gamer ID
    Join Date
    Mar 2011
    Location
    S̢͎̳̞̲͈̪̳̻ͮͩt̟̳̏ͬ̔&#
    Posts
    7,809
    Points
    7,616

    Contact info:

    Youtube Channel: http://www.youtube.com/kennethbgoodin

    Default

    Use else ifs.

    Or better yet a switch statement.

    0 Not allowed! Not allowed!
    ส็็็็็็็็็็็็็็็็็็็็็็็็็༼ ຈل͜ຈ༽ส้้้้้้้้้้้้้้้้้้้้้้้ส็็็็็็็็็็็็็็็็็็็็ ็็็็็༼ ຈل͜ຈ༽ส้้้้้้้้้้้้้้้้้้้้้้้

  4. #4
    Wii U Section Moderator
    Computer Engineer
    MrOwnership's Avatar

    Badge

    Join Date
    Jun 2011
    Location
    Maryland
    Posts
    1,435
    Points
    2,862
         User Info     Contact     Gamer ID
    Join Date
    Jun 2011
    Location
    Maryland
    Posts
    1,435
    Points
    2,862
    Gamer IDs

    Steam ID: MrOwnership Wii Code: MrOwnership

    Default

    You would be better off writing a function to convert decimal to binary and apply that binary to the LEDs. You don't want to have thousands of lines of the same code if you were to use say 10 LEDs instead of the 4 you have.

    0 Not allowed! Not allowed!

  5. #5
    Nintendo Section Moderator PvtRyan's Avatar

    Badge

    Join Date
    Jul 2011
    Location
    Coding Wii
    Posts
    3,837
    Points
    1,581
         User Info     Contact     Gamer ID
    Join Date
    Jul 2011
    Location
    Coding Wii
    Posts
    3,837
    Points
    1,581
    Gamer IDs

    PSN ID: gamer_pvtryan Steam ID: pvtryan_cl Wii Code: PvtRyan

    Contact info:

    Youtube Channel: http://www.youtube.com/xPvtRyanx

    Default

    Quote Originally Posted by null View Post
    Use else ifs.

    Or better yet a switch statement.
    I changed it and added the switch statement, and thinking of doing Ownerships sugg.

    Quote Originally Posted by MrOwnership View Post
    You would be better off writing a function to convert decimal to binary and apply that binary to the LEDs. You don't want to have thousands of lines of the same code if you were to use say 10 LEDs instead of the 4 you have.
    What I may do and this would be fairly the correct amount of coding but I will probably have it with a liquid crystal display and probably 5 leds.

    0 Not allowed! Not allowed!


    PS4 Profile:

  6. #6

    Retired Prophet
    ToxicJew.'s Avatar
    Join Date
    Mar 2011
    Location
    S̢͎̳̞̲͈̪̳̻ͮͩt̟̳̏ͬ̔&#
    Posts
    7,809
    Points
    7,616
         User Info     Contact     Gamer ID
    Join Date
    Mar 2011
    Location
    S̢͎̳̞̲͈̪̳̻ͮͩt̟̳̏ͬ̔&#
    Posts
    7,809
    Points
    7,616

    Contact info:

    Youtube Channel: http://www.youtube.com/kennethbgoodin

    Default

    MrOwnership's got a good point; even if you think you'll only use something once, write for re-usability.

    0 Not allowed! Not allowed!
    ส็็็็็็็็็็็็็็็็็็็็็็็็็༼ ຈل͜ຈ༽ส้้้้้้้้้้้้้้้้้้้้้้้ส็็็็็็็็็็็็็็็็็็็็ ็็็็็༼ ຈل͜ຈ༽ส้้้้้้้้้้้้้้้้้้้้้้้

  7. #7
    Nintendo Section Moderator PvtRyan's Avatar

    Badge

    Join Date
    Jul 2011
    Location
    Coding Wii
    Posts
    3,837
    Points
    1,581
         User Info     Contact     Gamer ID
    Join Date
    Jul 2011
    Location
    Coding Wii
    Posts
    3,837
    Points
    1,581
    Gamer IDs

    PSN ID: gamer_pvtryan Steam ID: pvtryan_cl Wii Code: PvtRyan

    Contact info:

    Youtube Channel: http://www.youtube.com/xPvtRyanx

    Default

    See the one thing is, I would like to do 2 seven segment displays with LED's and a keypad, but my question is could I do that on 1 arduino or would I need others.

    0 Not allowed! Not allowed!


    PS4 Profile:

  8. #8
    Wii U Section Moderator
    Computer Engineer
    MrOwnership's Avatar

    Badge

    Join Date
    Jun 2011
    Location
    Maryland
    Posts
    1,435
    Points
    2,862
         User Info     Contact     Gamer ID
    Join Date
    Jun 2011
    Location
    Maryland
    Posts
    1,435
    Points
    2,862
    Gamer IDs

    Steam ID: MrOwnership Wii Code: MrOwnership

    Default

    Quote Originally Posted by PvtRyan View Post
    See the one thing is, I would like to do 2 seven segment displays with LED's and a keypad, but my question is could I do that on 1 arduino or would I need others.
    The Uno has 14 GPIO pins so you can use two 7-segment LEDs. Plus I think you can use the 6 analog pins as GPIO pins as well. What type of keyboard are you talking about, the classic controller or a push button keyboard?

    0 Not allowed! Not allowed!

  9. #9
    Nintendo Section Moderator PvtRyan's Avatar

    Badge

    Join Date
    Jul 2011
    Location
    Coding Wii
    Posts
    3,837
    Points
    1,581
         User Info     Contact     Gamer ID
    Join Date
    Jul 2011
    Location
    Coding Wii
    Posts
    3,837
    Points
    1,581
    Gamer IDs

    PSN ID: gamer_pvtryan Steam ID: pvtryan_cl Wii Code: PvtRyan

    Contact info:

    Youtube Channel: http://www.youtube.com/xPvtRyanx

    Default

    Quote Originally Posted by MrOwnership View Post
    The Uno has 14 GPIO pins so you can use two 7-segment LEDs. Plus I think you can use the 6 analog pins as GPIO pins as well. What type of keyboard are you talking about, the classic controller or a push button keyboard?


    Like this but it's more of 13 pins, minus 1 for a ground.

    0 Not allowed! Not allowed!


    PS4 Profile:

Bookmarks

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -10. The time now is 06:51 PM.
Powered by vBulletin®
Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.