Show Posts
Pages: [1]
1  Using Arduino / Audio / Re: Volume Control (for buzzer) on: March 07, 2013, 11:15:19 am
Why not try Tone instead of Fading? Maybe you can canibalise a small speaker out of an old radio or something if you have no buzzer.

This seems to change the tone of the sounds, and not change the volume? as for cannibalizing a small speaker, I would very much love to do that, so I will smiley-grin



Thank you for the idea, I got it working smiley-grin and now all i have to do is make my up/down counter and hook em up smiley-grin and I'm done
2  Using Arduino / Audio / Volume Control (for buzzer) on: March 07, 2013, 10:55:09 am
So I read somewhere that you can control a buzzer sounds with a pot (so I'm guessing you can control it with the resistance).
Here: http://www.learningaboutelectronics.com/Articles/How-to-vary-the-volume-of-a-buzzer

So I had this idea, I am suppose to make an up/down binary counter application and I'm thinking about making a volume control application with a buzzer and said counter.

The idea is quite simple I have 15 levels max for the volume. I'm planning on using the code in arduino named fading.

This one
Code:
/*
 Fading
 
 This example shows how to fade an LED using the analogWrite() function.
 
 The circuit:
 * LED attached from digital pin 9 to ground.
 
 Created 1 Nov 2008
 By David A. Mellis
 modified 30 Aug 2011
 By Tom Igoe
 
 http://arduino.cc/en/Tutorial/Fading
 
 This example code is in the public domain.
 
 */


int ledPin = 9;    // LED connected to digital pin 9

void setup()  {
  // nothing happens in setup
}

void loop()  {
  // fade in from min to max in increments of 5 points:
  for(int fadeValue = 0 ; fadeValue <= 255; fadeValue +=5) {
    // sets the value (range from 0 to 255):
    analogWrite(ledPin, fadeValue);         
    // wait for 30 milliseconds to see the dimming effect   
    delay(30);                           
  }

  // fade out from max to min in increments of 5 points:
  for(int fadeValue = 255 ; fadeValue >= 0; fadeValue -=5) {
    // sets the value (range from 0 to 255):
    analogWrite(ledPin, fadeValue);         
    // wait for 30 milliseconds to see the dimming effect   
    delay(30);                           
  }
}


except i change the LED with a buzzer will it still work? (I wonder)
as for the application of the up/down counter. I have my basic idea for it and I need to know if this code will work(If i exchange the LED with a buzzer).(I have no buzzer in hand right now and I will be able to acquire 1 next week but this experiment is due next week xD).

Will it work?
3  Using Arduino / LEDs and Multiplexing / Re: Need Help 4-bit Binary Counter With Parallel Load on: February 09, 2013, 12:14:40 am
Finally got it to work and do what I wanted it to do.
Here's the code. (It's too long I know there is probably a way to make this shorter)
Code:
int LD = 6;
int swtch = 7;
int CLR = 8;
const int led[4] = {9,10,11,12};
const int in[4] = {2,3,4,5};
int counting, counting2, pin, x, y, z, h, j, k, l ;

void setup(){
  for (pin =0; pin < 4; pin++ )
   {
     pinMode (led[pin], OUTPUT);
   }
  for (pin =0; pin < 4; pin++ )
   {
     pinMode (in[pin], INPUT);
   }
  pinMode(swtch, INPUT);
  pinMode(CLR,INPUT);
  pinMode(LD, INPUT);
}
void loop(){
  x = digitalRead(swtch);
  y = digitalRead(CLR);
  z = digitalRead(LD);
  h = digitalRead(in[0]);
  j = digitalRead(in[1]);
  k = digitalRead(in[2]);
  l = digitalRead(in[3]);
  while(x==1){
     for ( counting = counting2; counting < 16; counting++)
         {
           x = digitalRead(swtch);
           if(x==1){
            LEDview();
            delay(1000);
           }else{
           break;
           }
          if (counting2 == 15){
                counting2 = 0;
             }
          else{
            counting2++;
          }
         }
  }
 
  if(y == 1){
    CLEAR();
    counting2 = 0;
  }else if(z == 1){
    digitalWrite(led[0], h);
    digitalWrite(led[1], j);
    digitalWrite(led[2], k);
    digitalWrite(led[3], l);
    counting2 = LOAD(h,j,k,l);
  }
       
 
   
}

void LEDview()
{
  digitalWrite (led[3], boolean ((counting & 8)>>3));
  digitalWrite (led[2], boolean ((counting & 4)>>2));
  digitalWrite (led[1], boolean ((counting & 2)>>1));
  digitalWrite (led[0], boolean (counting & 1));
}

int LOAD (int a, int b, int c, int d){
  int sum = a*1 + b*2 + c*4 + d*8;
  return sum;
}

void CLEAR() {
  for (pin =0; pin < 4; pin++ )
   {
     digitalWrite(led[pin], LOW);
   }
}
4  Using Arduino / LEDs and Multiplexing / Re: Need Help 4-bit Binary Counter With Parallel Load on: February 08, 2013, 08:29:00 pm
I have this circuit and gonna turn it to code





Quote
Code:
/* this function will compute for the decimal value of the 4 bit input
and give it to sum*/
int LOAD (int a, int b, int c, int d){
  int sum = d*8 + c*4 + b*2 + a;
  return sum;
Hint:- anything multiplied by zero is zero, no IFs are needed

And Thanks Grumpy Mike, you are so right about the LOAD function
5  Using Arduino / LEDs and Multiplexing / Re: Need Help 4-bit Binary Counter With Parallel Load on: February 07, 2013, 06:55:15 pm
I was sure those single = signs were double (==) yesterday ._. must have been more tired than I thought
Code:
/* set the pins */
int in1 = 2;
int in2 = 3;
int in3 = 4;
int in4 = 5;
int LD = 6;
int CNT = 7;
int CLR = 8;
int out1 = 9;
int out2 = 10;
int out3 = 11;
int out4 = 12;
int result = 0;
int counting = 0;
int counting2 = 0;


void setup(){
  pinMode (in1, INPUT);
  pinMode (in2, INPUT);
  pinMode (in3, INPUT);
  pinMode (in4, INPUT);
  pinMode (LD, INPUT);
  pinMode (CNT, INPUT);
  pinMode (CLR, INPUT);
  pinMode (out1, OUTPUT);
  pinMode (out2, OUTPUT);
  pinMode (out3, OUTPUT);
  pinMode (out4, OUTPUT);
}

void loop(){
 
   while(CLR == 0){ /* while CLR is LOW do this */
     /* if LOAD is HIGH read the inputs from in1-4 and give it to out1-4*/
      if(LD == 1){
         int j = digitalRead(in1);
         int k = digitalRead(in2);
         int l = digitalRead(in3);
         int m = digitalRead(in4);
         digitalWrite (out1, j);
         digitalWrite (out2, k);
         digitalWrite (out3, l);
         digitalWrite (out4, m);
         /*Get the value for count*/
         counting2 = LOAD(j, k, l, m);
      }else if(CNT == 1){ /* if count is HIGH do COUNT()*/
         COUNT();
      }else{ /*for error checking */
         digitalWrite (out1, LOW);
         digitalWrite (out2, HIGH);
         digitalWrite (out3, HIGH);
         digitalWrite (out4, LOW);
      }
  }
  /*when CLR is HIGH*/
  digitalWrite(out4, LOW);
  digitalWrite(out3, LOW);
  digitalWrite(out2, LOW);
  digitalWrite(out1, LOW);

}


/* this function will compute for the decimal value of the 4 bit input
and give it to sum*/
int LOAD (int a, int b, int c, int d){
  int sum = 0;
  if(a = 1){
    sum = sum + 1;
  }else{
    sum = sum;
  }
  if(b = 1){
    sum = sum + 2;
  }else{
    sum = sum;
  }
  if(c = 1){
    sum = sum + 4;
  }else{
    sum = sum;
  }
  if(d = 1){
    sum = sum + 8;
  }else{
    sum = sum;
  }
  return sum;
}

void COUNT(){
  /*this is the binary counter program.
counting is set to be = to counting2 since we would like to start from the last know data*/
  for ( counting = counting2; counting < 16; counting++)
 {
    LEDview();
    delay (1000); // The One second delay
 }
}
void LEDview(){
  digitalWrite (out4, boolean ((counting & 8)>>3));
  digitalWrite (out3, boolean ((counting & 4)>>2));
  digitalWrite (out2, boolean ((counting & 2)>>1));
  digitalWrite (out1, boolean (counting & 1));
}
6  Using Arduino / LEDs and Multiplexing / Re: Need Help 4-bit Binary Counter With Parallel Load on: February 07, 2013, 09:16:07 am
This is what I got. I haven't tested it out cause it's late and I don't have enough switches at the moment

Code:
int in1 = 2;
int in2 = 3;
int in3 = 4;
int in4 = 5;
int LD = 6;
int CNT = 7;
int CLR = 8;
int out1 = 9;
int out2 = 10;
int out3 = 11;
int out4 = 12;
int result = 0;
int counting = 0;
int counting2 = 0;

void setup(){
  pinMode (in1, INPUT);
  pinMode (in2, INPUT);
  pinMode (in3, INPUT);
  pinMode (in4, INPUT);
  pinMode (LD, INPUT);
  pinMode (CNT, INPUT);
  pinMode (CLR, INPUT);
  pinMode (out1, OUTPUT);
  pinMode (out2, OUTPUT);
  pinMode (out3, OUTPUT);
  pinMode (out4, OUTPUT);
}

void loop(){
  
   while(CLR = 0){
      if(LD = 1){
         int j = digitalRead(in1);
         int k = digitalRead(in2);
         int l = digitalRead(in3);
         int m = digitalRead(in4);
         digitalWrite (out1, j);
         digitalWrite (out2, k);
         digitalWrite (out3, l);
         digitalWrite (out4, m);
         counting2 = LOAD(j, k, l, m);
      }else if(CNT = 1){
         COUNT();
      }else{
         digitalWrite (out1, LOW);
         digitalWrite (out2, HIGH);
         digitalWrite (out3, HIGH);
         digitalWrite (out4, LOW);
      }
  }

}



int LOAD (int a, int b, int c, int d){
  int sum = 0;
  if(a = 1){
    sum = sum + 1;
  }else{
    sum = sum;
  }
  if(b = 1){
    sum = sum + 2;
  }else{
    sum = sum;
  }
  if(c = 1){
    sum = sum + 4;
  }else{
    sum = sum;
  }
  if(d = 1){
    sum = sum + 8;
  }else{
    sum = sum;
  }
  return sum;
}

void COUNT(){
  for ( counting = counting2; counting < 16; counting++)
 {
    LEDview();
    delay (1000); // The One second delay
 }
}
void LEDview(){
  digitalWrite (out4, boolean ((counting & 8)>>3));
  digitalWrite (out3, boolean ((counting & 4)>>2));
  digitalWrite (out2, boolean ((counting & 2)>>1));
  digitalWrite (out1, boolean (counting & 1));
}

void CLEAR(){
  digitalWrite(out4, LOW);
  digitalWrite(out3, LOW);
  digitalWrite(out2, LOW);
  digitalWrite(out1, LOW);
}


7  Using Arduino / LEDs and Multiplexing / Re: Need Help 4-bit Binary Counter With Parallel Load on: February 06, 2013, 05:51:16 am
Ok first I got a binary counter program in arduino (with the help of some arduino topics),
The Code(I'm pretty sure your familiar with this):
Code:
const int led[4] = {2,3,4,5};

int pin;
int counting;


void setup()

{
   for (pin =0; pin < 4; pin++ )
   {
     pinMode (led[pin], OUTPUT);
   }  
}

void loop()


{
 for ( counting = 0; counting < 16; counting++)
 {
    LEDview();
    delay (1000); // The One second delay
 }
}

void LEDview()


{
  digitalWrite (led[3], boolean ((counting & 8)>>3));
  digitalWrite (led[2], boolean ((counting & 4)>>2));
  digitalWrite (led[1], boolean ((counting & 2)>>1));
  digitalWrite (led[0], boolean (counting & 1));
}


Ok now i will add 7 inputs :

bit0
bit1
bit2
bit3

bits 0-3 will represent a four binary bit input

Load
Count
CLR

if load is high digital read the values of bit0-3 and output them on output (which is the led[4] in the program)
Now if we turn load to low , maintain the value last known.
if count is high, count from the last value (example: last input 5(decimal) - 0101(binary) and then i turn count on it will continue binary counting from 5(0101))
if clear is high all output is low


Oh and this is the circuit in which I am basing the program on.

http://www.expertcore.org/viewtopic.php?style=4&f=27&t=783
8  Using Arduino / LEDs and Multiplexing / Need Help 4-bit Binary Counter With Parallel Load on: February 05, 2013, 10:52:30 am
So i got the binary counter working. Now I just have to take and input (Load = HIGH) and if i turn on count it will continue counting from there..,

So i was thinking that i was thinking that I would take the 4 bit input then turn it to decimal and give the value to count.. is there anyway to do this?

I was thinking putting the HIGH or LOW values in an array or concatenate each input value and convert it to decimal.

If so how to convert from int to string, string to bit and then from string to int.
Pages: [1]