Pages: [1]   Go Down
Author Topic: Simple program help for beginner.  (Read 552 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

So I got an Arduino to get a basic understanding of programming and in the end I hope to move onto C. I have an Arduino Uno and all I want to do is make it count in binary and output this in 8 bits paralleled on it's output. I would also like 3 inputs for counting up, down and then sending all outputs high. I have very good analogue electronics knowledge but programming is totally new to me.

What I want from this system is volume control. The micro will drive 8 relays (with buffered outputs) with form a resistive ladder to attenuate the input signal going to my amplifier. So what will happen is the first relay will either send the signal through a potential divider of -1dB or bypass it the second will be -2dB and bypass the third -4dB and so on the 8th relay will be mute which will ground the signal.

I have no idea where to start whatsoever at all. I hope my brief makes sense could someone help me out?

Thanks
Boscoe
Logged

NE PA
Offline Offline
Full Member
***
Karma: 5
Posts: 156
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

If you have no programming experience then what you need to do is start small and work your way up. Read through the examples in the learning section of this site and try to get LEDs blinking, then work a button in, then two buttons, then a potentiometer, etc. Jumping into a large project fromt the start is just silly.

As for counting in binary there is some info in the shiftout example which might give you insight in how to do so with an Arduino.
Logged


UK
Offline Offline
Shannon Member
****
Karma: 184
Posts: 11173
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

That sounds like you'll have lots of relays clattering away, and all the circuits to power and control them. Have you considered using a digital potentiometer instead?
Logged

I only provide help via the forum - please do not contact me for private consultancy.

Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

That sounds like you'll have lots of relays clattering away, and all the circuits to power and control them. Have you considered using a digital potentiometer instead?

It's the best solution for high performance audio, there are dedicated volume chips the figures look good at 1KHz but aren't that great higher up. This volume control will have zero distortion in theory.

If you have no programming experience then what you need to do is start small and work your way up. Read through the examples in the learning section of this site and try to get LEDs blinking, then work a button in, then two buttons, then a potentiometer, etc. Jumping into a large project fromt the start is just silly.

As for counting in binary there is some info in the shiftout example which might give you insight in how to do so with an Arduino.

Thanks will do.
Logged

London
Offline Offline
Edison Member
*
Karma: 23
Posts: 1062
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I have an Arduino Uno and all I want to do is make it count in binary and output this in 8 bits paralleled on it's output.

Here's a code snippet for sequentially outputting 4 bits (0 - 15) to get you started:
Code:

     for (i=0; i<16; i++){
      //Disable output
        digitalWrite(12,HIGH)
      //set up LSB first
        digitalWrite(8, i&1);
     //shift right = divide by 2
        digitalWrite(9, (i/2)&1);
     //shift right twice =divide by 4
        digitalWrite(10, (i/4)&1);
      //shift right four times =divide by 8 for MSB
        digitalWrite(11, (i/8) &1);
     //enable output
        digitalWrite(12,LOW)
    }
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 238
Posts: 24350
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Or, more intuitively
Code:
digitalWrite(8, i & 1);
        digitalWrite(9, i & 2);
        digitalWrite(10, i & 4);
        digitalWrite(11, i & 8);
     //enable output
        digitalWrite(12,LOW)
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

London
Offline Offline
Edison Member
*
Karma: 23
Posts: 1062
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Or, more intuitively
Code:
digitalWrite(8, i & 1);
        digitalWrite(9, i & 2);
        digitalWrite(10, i & 4);
        digitalWrite(11, i & 8);
     //enable output
        digitalWrite(12,LOW)

Thanks for that, AWOL.
I had assumed that only a 1 is equivalent to HIGH, whereas it appears from your code that any value greater than 0 is read as HIGH.
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 238
Posts: 24350
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
it appears from your code that any value greater than 0 is read as HIGH.
Almost - in C, the convention is that any non-zero value, positive or negative, is interpreted as "true".
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

London
Offline Offline
Edison Member
*
Karma: 23
Posts: 1062
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
it appears from your code that any value greater than 0 is read as HIGH.
Almost - in C, the convention is that any non-zero value, positive or negative, is interpreted as "true".

I was thinking solely of 'unsigned ints', duh! Thanks again.
Logged

Offline Offline
Full Member
***
Karma: 0
Posts: 138
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I know you are just starting out, but I would suggest you study C++ and not C since the Arduino platform is based on it.  I recently purchased a C++ reference book that has been quite helpful.  In addition, this site is very good:
http://www.learncpp.com

But before you go into C++ too deep, I agree with what has been said.  Focus on the examples provided on the Arduino IDE (interractive design environment).  They have helped me a bunch.
Logged

Pages: [1]   Go Up
Jump to: