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
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.

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:
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
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.

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_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
      //start bits
      //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

//transmit function
void bit_tx(int num)
      case 0://0 pulse
        digitalWrite(tx, LOW);
        digitalWrite(tx, HIGH);
      case 1://1 pulse
        digitalWrite(tx, LOW);
        digitalWrite(tx, HIGH);
      case 2://start-stop pulse
        digitalWrite(tx, LOW);
        digitalWrite(tx, HIGH);

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


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
      if(digitalRead(rx)==1)//check data stream valid
          digitscan(display_val, 4, dot_val);

  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_keyC_last = rx_keyC;
  for(int i=0;i<=1024;i++)//caputre data stream
      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
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

//add up long pulses as 2^ for 4 bytes





  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
MIDI.setInputChannel(OMNI);//set input if used

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

To send CC 74 data

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