Show Posts
Pages: [1]
1  Forum 2005-2010 (read only) / Syntax & Programs / Re: How does one ignore a void value? on: December 10, 2010, 10:25:01 pm
Ah. Yeah, that would be the problem. Thanks for the quick (and correct) response! It's nice to get a fresh pair of eyes on a problem smiley
2  Forum 2005-2010 (read only) / Syntax & Programs / How does one ignore a void value? on: December 10, 2010, 09:24:37 pm
Hey there everybody,
I've been working with the parallax rfid reader/writer I just got  smiley it's super awesome, and I can read data fine, but now I want to try to write it. I decided to write a function to do so (hooray for me!) but I can't get it to work - the error I keep getting is as follows:

rfid.cpp: In function 'void do_rfid_write(char*)':
rfid:125: error: void value not ignored as it ought to be
rfid:128: error: void value not ignored as it ought to be

Here's the code for the write function, and I can include the rest of the code if anyone's interested. How can I test to see if something is void, and then ignore it if so?

Quote
void do_rfid_write(char indata[]){
  for(int i = 0; i < sizeof(indata)/sizeof(char) && i < maxAddress*4; i++){
    sendWriteCommand(i/4); // this is because we can store 4 chars (or bytes) per address

    while(!mySerial.available()){
    }

    statusCode = mySerial.print(indata); // <- This is line 125, where it fails first
    while(statusCode != ERR_OK){
      sendWriteCommand(i);
      statusCode = mySerial.print(indata); // <- This is where it fails second
    }

    Serial.print("wrote address ");
    Serial.println(i);
  }
  Serial.println("Finished Write");
}

3  Forum 2005-2010 (read only) / Syntax & Programs / Re: Too Many Arguments to Function? on: February 07, 2009, 12:58:47 pm
Quote
The variable is an integer.  It cannot store fractional parts.  The math done on an integer variable is done only with integers, and so any fraction is immediately discarded.
Quote
The formula above just helped you round DOWN to the nearest 100.

Halley, thanks for the information. Sorry, Mikalhart, I didn't realize that int's can't hold fractional parts, so your code is actually perfect for what I'm trying to do. Thanks again everybody,

(the_downsmeister)
4  Forum 2005-2010 (read only) / Syntax & Programs / Re: Too Many Arguments to Function? on: February 07, 2009, 11:45:41 am
Hey mikalhart-
thanks for the help. Your code is not what I want to accomplish; I want the beats delay to be only those 10 lengths, not every length in between. When you have waitFunction()
Code:
   return 100 * (waitVal / 100);

waitVal remains the same. Dividing waitVal by 100 and then multiplying it by 100 returns what was on the line above,
Code:
   waitVal = waitVal * 1000 / 256;
because in effect your multiplying it by 1.

Even though your code samples weren't exactly what I was looking for, you helped solve the problem; I WAS passing values into the functions where you couldn't see them:
Code:
void loop()
{
  waitVal = analogRead(waitPot);
  waitFunction(waitVal);
  pitchVal = analogRead(pitchPot);
  freqFunction(pitchVal);
  digitalWrite(speakerPin, HIGH); // pulses the speaker HIGH (on)
  delayMicroseconds(freqDelay); // waits for pitchDelay microseconds
  digitalWrite(speakerPin, LOW); // pulses the speaker LOW (off)
  delayMicroseconds(freqDelay); // waits for pitchDelay microseconds
  delay(waitFinal);
}

Removing the waitVal from waitFunction() and pitchVal from freqFunction() let the code compile perfectly. Thanks so much for the help.

(the_downsmeister)

5  Forum 2005-2010 (read only) / Syntax & Programs / Too Many Arguments to Function? on: February 06, 2009, 11:49:04 pm
Hey everybody,
I've been working on a project to make noise with an arduino by hooking it up to a speaker and some pots. Email me if you're interested in the full code, but here is the part that's effected:
Code:
int waitTable[] = {0, 100, 200, 300, 400, 500, 600, 700, 800, 900};

int waitFunction()
{
  waitVal = analogRead(waitPot);
  if(waitVal >=0 && waitVal <=255)
  {
    if(waitVal <= 25)
    {
      waitFinal = waitTable[0];
      return(waitFinal);
    }
    else if(waitVal > 25 && waitVal <= 50)
    {
      waitFinal = waitTable[1];
      return(waitFinal);
    }
    else if(waitVal > 50 && waitVal <= 75)
    {
      waitFinal = waitTable[2];
      return(waitFinal);
    }
    else if(waitVal > 75 && waitVal <= 100)
    {
      waitFinal = waitTable[3];
      return(waitFinal);
    }
    else if(waitVal > 100 && waitVal <= 125)
    {
      waitFinal = waitTable[4];
      return(waitFinal);
    }
    else if(waitVal > 125 && waitVal <= 151)
    {
      waitFinal = waitTable[5];
      return(waitFinal);
    }
    else if(waitVal > 151 && waitVal <= 177)
    {
      waitFinal = waitTable[6];
      return(waitFinal);
    }
    else if(waitVal > 177 && waitVal <= 203)
    {
      waitFinal = waitTable[7];
      return(waitFinal);
    }
    else if(waitVal > 203 && waitVal <= 229)
    {
      waitFinal = waitTable[8];
      return(waitFinal);
    }
    else if(waitVal > 229)
    {
      waitFinal = waitTable[9];
      return(waitFinal);
    }
  }
}
When I try to compile the program, the following error pops up:

 In function 'void loop()':
error: too many arguments to function 'int waitFunction()'


Is there a more efficient way to write this code? I'm making sound by pulsing a speaker HIGH and then LOW with an extremely small delay measured in another function, but the waitFunction() allows me to separate strings of noise into beats. I could just set the delay directly proportional to the input from the waitPot, but I'd have it this way if possible. Am I missing an obvious solution that will let me keep my code's functionality the same?

(the_downsmeister)
6  Forum 2005-2010 (read only) / Workshops / Philadelphia Arduino on: January 30, 2009, 10:48:09 am
is anyone involved with Arduino around the Philadelphia area? I searched but could not find any mention of it on the forums. If anyone is interested in setting up a meeting for Arduino enthusiasts in and around Philly post a reply here.
7  Forum 2005-2010 (read only) / Exhibition / Arduinstrument on: March 18, 2009, 07:29:24 am
Hey guys,
here's a program I've worked on and off on for the past couple of months. When connected as explained in the code, twisting a pot will change the tone and twisting a different pot changes the length of the note. Code:
Quote

 
/*
-- The Basic Arduinstrument --
The following code lets the user determine the pitch and delay for a tone to play out of a speaker.
When [potentiometers are connected as described below to pins 19 and 18 they allow the user
to determine the pitch of a tone and the length of a tone for a range of tones calculated
in this program. To expand the range of tones, change maxTone at the beginning.
For volume control, connect a potentiometer with terminal 1 to pin 9, wiper to the positive
wire on your speaker, and terminal 3 to ground. This will attenuate the volume of the
tone generated by the arduino.

 Modifications:
1. Buttons - this code could easly be modified to change the maxTone depending on what
             momentary switch is pressed, or to only play a tone when a button is pressed.
2. LED's - connect a series of LED's to pins on the arduino and have their value correlate
           to the value of the different potentiometers. An LED could pulse with HIGH and LOW.
3. Anything else - this code is yours to do with what you want; please give me some credit.
*/
int speakerPin = 9; // 8 ohm speaker; positive to pin 9, negative to Gnd

int pitchPot = 19; // potentiometer to determine pitch; left terminal to +5v, wiper to analog 5, right terminal to Gnd
int pitchVal = 0; // variable to hold the value of pitchPot
int pitchDelay = 0; // variable to hold the final value to delay between pulses HIGH and LOW
int maxTone = 1000; // lower = higher pitch, higher = lower pitch

int waitPot = 18; // potentiometer to determine delay between beats; left terminal to +5v, wiper to analog 4, right terminal to Gnd
int waitVal = 0; // variable to hold the value of waitPot
int waitDelay = 0; // variable to hold hte final value to wait between beats
int maxDelay = 1000; // maximum time per beat (in milliseconds)

unsigned long startTime = 0; // variable to hold the start time of pulsing the speaker
unsigned long endTime = 0; // variable to hold the end time of pulsing the speaker


void setup()
{
  pinMode(speakerPin, OUTPUT); // sets the speaker as an output
  pinMode(pitchPot, INPUT); // allows a value to be determined from pitchPot
  pinMode(waitPot, INPUT);// allows a value to be determined from waitPot
}

void loop()
{
  startTime = millis(); // takes the time
  while(endTime - startTime < waitDelay) // while the time difference between the current time and the time before the loop is less than the desired time
  {
    endTime = millis(); // samples the current time
    pitchVal = analogRead(pitchPot); // reads the potentiometer hooked up to analog 5
    pitchDelay = maxTone - (pitchVal * (maxTone / pitchVal)); // calculates how long to delay between pulses
    waitVal = analogRead(waitPot); // reads the potentiometer hooked up to analog 4
    waitDelay = - maxDelay + (waitVal * (maxDelay / waitVal)); // calculates how long between tones
    digitalWrite(speakerPin, HIGH); // pulses the speaker HIGH
    delayMicroseconds(pitchDelay); // waits; the time it waits determines the pitch (longer = lower)
    digitalWrite(speakerPin, LOW); // pulses the speaker LOW
    delayMicroseconds(pitchDelay); // waits; the time it waits determines the pitch
  }
  delayMicroseconds(waitDelay); // waits for the same amount of time the speaker played a tone
  endTime = 0; // resets endTime
}


 
8  Forum 2005-2010 (read only) / Frequently-Asked Questions / Re: touch sensitive resistor? on: January 27, 2009, 08:25:30 pm
Estranged seems to have hit it on the nose. That's exactly what I've been looking for, thank you very much.

Quote
PWM (Pulse-Width Modulation) is a method of generating an analog output from a digital output pin.  There are no "PWM inputs", it just doesn't make sense to say that.


You're exactly right, Anachrocomputer, I meant to say analog readable (I'm using the analog read function). Sorry for the error, I just started with arduino and I'm still learning my terms. Thanks again,

- (the_downsmeister)
9  Forum 2005-2010 (read only) / Frequently-Asked Questions / touch sensitive resistor? on: January 26, 2009, 10:20:42 pm
Hey everybody,
I've been trying to build a small musicbox out of an arduino and some buttons and things. First design used 8 different buttons to trigger different tones and then two pots to control delay between beeps and pitch variation. Only having remembered (misremembered?) that I saw some sort of PWM readable touch sensor. Ideally, I'd have it hooked up to the arduino so that the further along on the touch strip the higher the pitch and another one for looping, but I can't find any online. Maybe the problem is that I don't know what to look for? If anyone can tell me anything about what I'm looking for (if it exists :o) that would be great.
- (the_downsmeister)
Pages: [1]