Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better instructions #2

Open
julesmoretti opened this issue Jun 27, 2019 · 3 comments
Open

Better instructions #2

julesmoretti opened this issue Jun 27, 2019 · 3 comments

Comments

@julesmoretti
Copy link

Could you please provide a clearer example using Serial to print the result, please?

Thank you.

@waspinator
Copy link
Owner

try this for printing out which channel is currently being used.

#include <CD74HC4067.h>

               // s0 s1 s2 s3
CD74HC4067 my_mux(4, 5, 6, 7);  // create a new CD74HC4067 object with its four control pins
const int g_common_pin = A0; // select a pin to share with the 16 channels of the CD74HC4067

void setup()
{
    pinMode(g_common_pin, OUTPUT); // set the initial mode of the common pin.
	                               // This can be changed in loop() for for each channel.

    // initialize serial communications at 9600 bps
    Serial.begin(9600);
}

void loop()
{
    digitalWrite(g_common_pin, HIGH);

    for (int i = 0; i < 16; i++) {
        my_mux.channel(i);
        Serial.print("channel = ");
        Serial.println(i);
        delay(1000);
    }
}

@julesmoretti
Copy link
Author

Thank you, that works for letting me know which channel but then somehow to read it is not working. I have tried to follow also this tutorial with no luck: http://blog.codebender.cc/2014/01/30/mux74hc4067/ the button press one, when hooking things up with buttons I got from Amazon it is not working. (https://www.amazon.com/gp/product/B018RYSTD0/ref=ppx_yo_dt_b_asin_title_o08_s00?ie=UTF8&psc=1)

when I try their tutorial and press the first button other inputs are read as pressed even though I only pressed one button.

Some people talks about debouncing but.... not super straight forward.

Also when I run it with serial it is not live. when I click button down it takes a while to apear, it is super strange.

My code is as follow based on the above:

#include <CD74HC4067.h>

               // s0 s1 s2 s3
CD74HC4067 my_mux(4, 5, 6, 7);  // create a new CD74HC4067 object with its four control pins
const int g_common_pin = 8; // select a pin to share with the 16 channels of the CD74HC4067

int sig = 3;
int val = 0;

void setup()
{
    pinMode(g_common_pin, OUTPUT); // set the initial mode of the common pin.
                                 // This can be changed in loop() for for each channel.

    // initialize serial communications at 9600 bps
    Serial.begin(9600);
}

void loop()
{
    digitalWrite(g_common_pin, HIGH);

    for (int i = 0; i < 4; i++) {
      if (i == 0) Serial.println("--------");
        my_mux.channel(i);
        val = digitalRead(sig);
        Serial.print("channel = ");
        Serial.print(i);
        Serial.print(" - val: ");
        Serial.print(val);
        Serial.print(" - ");
        // delay(200);
        if (i == 3) Serial.println("");
    }
}

Thank you for the response and help :)

@bsvdoom
Copy link
Contributor

bsvdoom commented Jul 23, 2023

add some delay between the two lines:
my_mux.channel(i);
delay(10);
val = digitalRead(sig);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants