Show Posts
Pages: [1] 2 3 4
1  Forum 2005-2010 (read only) / Syntax & Programs / Re: Using functions (noob help with syntax) on: January 10, 2010, 11:14:45 am
In plain English, the part in front of the function is the type you expect to receive and the part in the parenthesis is the type you send. Void is just another way of saying nothing, so void function(void) doesn't expect any input and will not send anything back. Just a blank () implies (void).

This is probably the best starting reference http://www.cplusplus.com/doc/tutorial/
2  Forum 2005-2010 (read only) / Syntax & Programs / Re: uint8_t, uint16_t, int, unsigned int on: December 30, 2009, 03:15:13 pm
This should explain everything.
http://en.wikipedia.org/wiki/Stdint.h

As it says, using those methods make your code more portable because it can be reused on other platforms because they might have a different idea of what int and others mean.
3  Forum 2005-2010 (read only) / Syntax & Programs / Re: Newbie ?: Rrun stepper program just once? on: December 30, 2009, 12:16:14 am
In the loop section you would just give it something that never ends like:
while(1);
4  Forum 2005-2010 (read only) / Syntax & Programs / Re: Is it possible to run a "make clean"? on: July 31, 2009, 01:34:02 pm
That's a definite hassle and it either can't do it or I just can't find the option.
One thing I've noticed is that when you switch board type it deletes and remakes all the object files.
So one shortcut would be to just switch the board type then switch it back.
5  Forum 2005-2010 (read only) / Syntax & Programs / Re: First sketch by total n00b on: July 29, 2009, 12:14:02 pm
It's not going to do what you want in its current state. Get rid of the 'for' loop completely.

Define the 'int state;' for the button at the top with the rest then just do a state=digitalRead(button); in the loop.

But the led writes inside an if() testing for x==1 and the other states.

Then have an
  
  if(state==1){delay(300);x++;}//delay for button debounce
to advance at every button press. X will advance then the leds will do what is inside their if(x==1) statements.

At the end add
  if(x>2)x=0;
so it resets and starts over. x starts at 0 so 3 states would start at if(x==0)

With this flow it will loop forever and switch mode every button press.

6  Forum 2005-2010 (read only) / Syntax & Programs / Re: First sketch by total n00b on: July 29, 2009, 11:51:30 am
You are just misplacing some brackets so it thinks you are trying to define something outside of the loop().
It can also be cleaned up and simplified to about half that size.
7  Forum 2005-2010 (read only) / Syntax & Programs / Re: First sketch by total n00b on: July 29, 2009, 11:40:14 am
As far as obvious syntax, the 'for' loop should be x<2 (for 3 counts 0,1,2) because it loops while that is the condition. The x=1 stuff inside the if() should be x==1 like you have the button state. There might be some other technical problems but you are on the right thought path.
8  Forum 2005-2010 (read only) / Syntax & Programs / Re: Arduino 24LC128 eeprom location on: July 27, 2009, 10:41:17 am
Oops, thanks for the correction, I forgot I already counted the 0 as a digit.
9  Forum 2005-2010 (read only) / Syntax & Programs / Re: Arduino 24LC128 eeprom location on: July 27, 2009, 12:01:38 am
128k is actual 131070bits so you divide that by 8 and -1 to start at 0, with a 2 byte address it should be 0 to 16382.

Be sure to check the write delay needed between cycles, probably 5ms,  or there will be a lot of missing writes.

10  Forum 2005-2010 (read only) / Syntax & Programs / Re: Reading status on pellet-burner on: July 22, 2009, 07:15:31 am
With pulses that long it would probably be easiest to just have a variable set to equal millis when high, then reset and read the difference when it goes low. It can just be part of the main program loop because there can be 999ms error and still get the correct state.
11  Forum 2005-2010 (read only) / Interfacing / Re: Testing RF links on: June 01, 2009, 04:52:44 pm
I use software to transmit with a 4 byte protocol. It uses longer start/stop bits so the RX knows when it has the full signal. To check it on the receiver side you can just use the pulseIn to capture an array of LOW pulses and see long and short for 0 and 1. Decrease the timing in the bit_tx function until it becomes unstable then you can figure out the maximum reliable rate for your application. Keep in mind the inverted signal so with the data on the HIGH TX side it will be LOW on the RX.

This transmits MSB first, I had a reason for that but I can't remember what it was. It acts as a beacon that pings every 500ms and the receiver can listen at any random window and get the full data stream. I use the UART for something else so this is all in software.


Quote
int tx=6;//TX pin
byte tx_val[4]={B10001001,B11010001,B11011111,B1111111};//4 data bytes
unsigned long tx_time;

void setup()
{
  pinMode(tx, OUTPUT);
  digitalWrite(tx, LOW);

}

void loop()
{
//TX
  tx_val[3]=tx_val[0]^tx_val[1]^tx_val[2];//store CRC in 4th byte
  if(millis()-tx_time>500)//send TX pulse every 500ms
    {
      tx_time=millis();  
      //start bits
      bit_tx(2);
      bit_tx(2);
      //start data
        for(int i=0;i<4;i++)//cycle 4 bytes
          {
            for(int j=7;j>=0;j--)//cycle 8 bits
              {
                if((tx_val>>j)&B00000001==1)bit_tx(1);//check for 1 and transmit 1
                  else bit_tx(0);//transmit 0
              }
          }
      //stop bits
      bit_tx(2);
      bit_tx(2);
    }
}

//transmit function
void bit_tx(int num)
{
  switch(num)
    {
      case 0://0 pulse
        digitalWrite(tx, LOW);
        delayMicroseconds(500);
        digitalWrite(tx, HIGH);
        delayMicroseconds(500);
      break;
      case 1://1 pulse
        digitalWrite(tx, LOW);
        delayMicroseconds(500);
        digitalWrite(tx, HIGH);
        delayMicroseconds(1500);
      break;
      case 2://start-stop pulse
        digitalWrite(tx, LOW);
        delay(10);
        digitalWrite(tx, HIGH);
        delay(10);
      break;
    }
}


The RX code isn't optimized yet because it's hacked together from my IR receiver code.

Quote

int rx=7;//RX pin
int rx_val;
int rx_decode[128];
byte rx_byte[4];
unsigned int rx_key=0;
int rx_keyC = 99;
int rx_keyC_last = 99;
unsigned long rx_time=millis();
int rx_count=0;
int rx_index=0;
int rx_endmark=0;
int rx_stream_last=0;
byte rx_CRC=0;

void setup()
{

  pinMode(rx, INPUT);

}

void loop()
{

  rx_keyC = 99;//set null
  if(digitalRead(rx)==0)//check for data
    {
      delay(15);
      if(digitalRead(rx)==1)//check data stream valid
        {
          dig_count=0;
          digitscan(display_val, 4, dot_val);
          rxscan();
        }
    }

  if(rx_keyC==0)//do if valid data stored
    {

    }



}
void rxscan()
{
  for(int i=0;i<4;i++)rx_byte=0;
  for(int i=0;i<=48;i++)
    {
      rx_decode=0;
    }
  rx_keyC_last = rx_keyC;
  rx_key=0;
  rx_count=0;
  rx_index=0;
  rx_endmark=0;
  rx_CRC=0;
  
  for(int i=0;i<=1024;i++)//caputre data stream
    {
      rx_stream_last=rx_val;
      rx_val = digitalRead(rx);
      if(rx_val==0 && rx_stream_last==0)rx_count++;//count low pulse
      if(rx_val==1 && rx_stream_last==1)rx_count++;//count high pulse
      if(rx_val==0 && rx_stream_last==1){rx_count++;rx_decode[rx_index]=rx_count;rx_index++;rx_count=0;}//store pulse count
      if(rx_index>48)goto RX_ENDMARK;//break if overflow
      delayMicroseconds(250);//half of low pulse timing
    }
RX_ENDMARK:;
for(int i=1;i<48;i++)
  {
    if(rx_decode>70&&rx_decode<100&&rx_decode[i-1]>0&&rx_decode[i-1]<10)rx_endmark=i;//verify stop bit and set end
  }

  if(rx_endmark<16){rx_key=0;rx_keyC=98;}//data stream too short to be valid

  rx_count=0;
  rx_key=0;
//add up long pulses as 2^ for 4 bytes
  if(rx_decode[rx_endmark-1]>5&&rx_decode[rx_endmark-1]<10){rx_byte[3]+=pow(2,0);}
  if(rx_decode[rx_endmark-2]>5&&rx_decode[rx_endmark-2]<10){rx_byte[3]+=pow(2,1);}
  if(rx_decode[rx_endmark-3]>5&&rx_decode[rx_endmark-3]<10){rx_byte[3]+=pow(2,2);}
  if(rx_decode[rx_endmark-4]>5&&rx_decode[rx_endmark-4]<10){rx_byte[3]+=pow(2,3);}
  if(rx_decode[rx_endmark-5]>5&&rx_decode[rx_endmark-5]<10){rx_byte[3]+=pow(2,4);}
  if(rx_decode[rx_endmark-6]>5&&rx_decode[rx_endmark-6]<10){rx_byte[3]+=pow(2,5);}
  if(rx_decode[rx_endmark-7]>5&&rx_decode[rx_endmark-7]<10){rx_byte[3]+=pow(2,6);}
  if(rx_decode[rx_endmark-8]>5&&rx_decode[rx_endmark-8]<10){rx_byte[3]+=pow(2,7);}

  if(rx_decode[rx_endmark-9]>5&&rx_decode[rx_endmark-9]<10){rx_byte[2]+=pow(2,0);}
  if(rx_decode[rx_endmark-10]>5&&rx_decode[rx_endmark-10]<10){rx_byte[2]+=pow(2,1);}
  if(rx_decode[rx_endmark-11]>5&&rx_decode[rx_endmark-11]<10){rx_byte[2]+=pow(2,2);}
  if(rx_decode[rx_endmark-12]>5&&rx_decode[rx_endmark-12]<10){rx_byte[2]+=pow(2,3);}
  if(rx_decode[rx_endmark-13]>5&&rx_decode[rx_endmark-13]<10){rx_byte[2]+=pow(2,4);}
  if(rx_decode[rx_endmark-14]>5&&rx_decode[rx_endmark-14]<10){rx_byte[2]+=pow(2,5);}
  if(rx_decode[rx_endmark-15]>5&&rx_decode[rx_endmark-15]<10){rx_byte[2]+=pow(2,6);}
  if(rx_decode[rx_endmark-16]>5&&rx_decode[rx_endmark-16]<10){rx_byte[2]+=pow(2,7);}

  if(rx_decode[rx_endmark-17]>5&&rx_decode[rx_endmark-17]<10){rx_byte[1]+=pow(2,0);}
  if(rx_decode[rx_endmark-18]>5&&rx_decode[rx_endmark-18]<10){rx_byte[1]+=pow(2,1);}
  if(rx_decode[rx_endmark-19]>5&&rx_decode[rx_endmark-19]<10){rx_byte[1]+=pow(2,2);}
  if(rx_decode[rx_endmark-20]>5&&rx_decode[rx_endmark-20]<10){rx_byte[1]+=pow(2,3);}
  if(rx_decode[rx_endmark-21]>5&&rx_decode[rx_endmark-21]<10){rx_byte[1]+=pow(2,4);}
  if(rx_decode[rx_endmark-22]>5&&rx_decode[rx_endmark-22]<10){rx_byte[1]+=pow(2,5);}
  if(rx_decode[rx_endmark-23]>5&&rx_decode[rx_endmark-23]<10){rx_byte[1]+=pow(2,6);}
  if(rx_decode[rx_endmark-24]>5&&rx_decode[rx_endmark-24]<10){rx_byte[1]+=pow(2,7);}

  if(rx_decode[rx_endmark-25]>5&&rx_decode[rx_endmark-25]<10){rx_byte[0]+=pow(2,0);}
  if(rx_decode[rx_endmark-26]>5&&rx_decode[rx_endmark-26]<10){rx_byte[0]+=pow(2,1);}
  if(rx_decode[rx_endmark-27]>5&&rx_decode[rx_endmark-27]<10){rx_byte[0]+=pow(2,2);}
  if(rx_decode[rx_endmark-28]>5&&rx_decode[rx_endmark-28]<10){rx_byte[0]+=pow(2,3);}
  if(rx_decode[rx_endmark-29]>5&&rx_decode[rx_endmark-29]<10){rx_byte[0]+=pow(2,4);}
  if(rx_decode[rx_endmark-30]>5&&rx_decode[rx_endmark-30]<10){rx_byte[0]+=pow(2,5);}
  if(rx_decode[rx_endmark-31]>5&&rx_decode[rx_endmark-31]<10){rx_byte[0]+=pow(2,6);}
  if(rx_decode[rx_endmark-32]>5&&rx_decode[rx_endmark-32]<10){rx_byte[0]+=pow(2,7);}


  rx_CRC=rx_byte[0]^rx_byte[1]^rx_byte[2];

  if(rx_byte[3]==rx_CRC&&rx_byte[3]!=0)//check CRC and valid data
    {
      rx_keyC=0;//valid rx_byte[] data stored

    }

}

12  Forum 2005-2010 (read only) / Interfacing / Re: Testing RF links on: June 01, 2009, 02:40:45 pm
I have the same exact RF set and notice the receiver is inverted. Also, the data sheet shows 20ms at VCC turn on time but I have needed some dummy bytes at each transmission start along with a CRC byte at the end.

It's rock solid after that but I use a software method so it's more flexible to filter noise. I connect everything straight pin to pin with no pull up/down resistors.

I went from almost smashing it with a hammer to being extremely pleased within an hour so just stick with it.
13  Forum 2005-2010 (read only) / Interfacing / Re: 4051 button Matrix on: July 22, 2009, 10:02:11 am
You would use one 4051 to scan columns and the 2nd 4051 to scan rows just like any standard matrix keypad. Each column is linked and each row is linked for the matrix.

Then you set the common IN/OUT 4051 columns to a digital input pin, set the 2nd common IN/OUT 4051 rows to a digital output pin.

The program would switch on a row, scan all 8 columns for a HIGH and tell if one or more is pressed, then move to the next row and scan.
14  Forum 2005-2010 (read only) / Interfacing / Re: MIDI lib code help on: February 02, 2010, 02:04:40 am
Usually there is some basic example library code if you goto the file->examples-> from the Arduino IDE.
Then the .h file will give an overview of the functions and you go through the .cpp file to figure out exactly what they do.

15  Forum 2005-2010 (read only) / Interfacing / Re: MIDI lib code help on: February 02, 2010, 01:04:31 am
I'm assuming you're using the library from the playground.

That MIDI library sets the serial rate so replace Serial.begin with
Code:
MIDI.begin();
MIDI.setInputChannel(OMNI);//set input if used

The MIDI.send function is the only one you need to use.

To send CC 74 data
Code:
MIDI.send(CC,74,VALUE,CHANNEL);

Look in the MIDI.h for other defined data types because the data type is offset from 0x80 and not the actual standard MIDI value.

Beyond that it would help to refine the code to thin the data and not flood the port. The delay works fine for now but it's still sending an enormous amount of data if it will be recorded with a sequencer.
Pages: [1] 2 3 4