Combine an rpm reading sketch and the blinkm communicator

Hello, im trying to make a bike computer for my bike, but i would also like it to program my blinkm in the same sketch. I made this, but now it just doesnt work at all (it runs, but doesnt program the LED, and i havent tested counting yet)

#include "BlinkM_funcs.h"
#include "Wire.h"

#define CMD_START_BYTE  0x01

int blinkm_addr = 0x09;

byte serInStr[32];  // array that will hold the serial input string

int ledPin = 13;

 volatile byte rpmcount;
 unsigned int rpm;
 unsigned long timeold;
 void setup()
   digitalWrite(2, HIGH);
   attachInterrupt(0, rpm_fun, RISING);
   rpmcount = 0;
   rpm = 0;
   timeold = 0;
 pinMode(ledPin, OUTPUT);
    } else {
    // FIXME:
    BlinkM_setAddress( blinkm_addr );  // comment out to not set address
    byte rc = BlinkM_checkAddress( blinkm_addr );
    if( rc == -1 ) 
        Serial.println("no response");
    else if( rc == 1 ) 
        Serial.println("addr mismatch");

    Serial.println("BlinkMCommander ready");
#ifdef DEBUG
    Serial.println("DEBUG MODE");
 void loop()
   if (rpmcount >= 20) { 
     //Update RPM every 20 counts, increase this for better RPM resolution,
     //decrease for faster update
     rpm = 30*1000/(millis() - timeold)*rpmcount;
     timeold = millis();
     rpmcount = 0;
       int num;
    //read the serial port and create a string out of what you read
    num = readCommand(serInStr);
    if( num == 0 )   // see if we got a proper command string yet

    digitalWrite(ledPin,HIGH);  // say we're working on it
    byte addr    = serInStr[1];
    byte sendlen = serInStr[2];
    byte recvlen = serInStr[3];
    byte* cmd    = serInStr+4;
#ifdef DEBUG
    Serial.print(" addr:"); Serial.print(addr,HEX);
    Serial.print(" sendlen:"); Serial.print(sendlen,HEX);
    Serial.print(" recvlen:"); Serial.print(recvlen,HEX);
    Serial.print(" cmd[0..7]:"); Serial.print(cmd[0],HEX);
    Serial.print(","); Serial.print(cmd[1],HEX); 
    Serial.print(","); Serial.print(cmd[2],HEX);
    Serial.print(","); Serial.print(cmd[3],HEX);
    Serial.print(","); Serial.print(cmd[4],HEX);
    Serial.print(","); Serial.print(cmd[5],HEX);
    Serial.print(","); Serial.print(cmd[6],HEX);
    Serial.print(","); Serial.println(cmd[7],HEX);

    BlinkM_sendCmd(addr, cmd, sendlen);

    // if looking for a response, get it
    if( recvlen!=0 ) {
        byte resp[16];
        int rc = BlinkM_receiveBytes(addr, resp, recvlen);
        for( int i=0; i<recvlen; i++) 

    for(int i=0; i<30;i++)
        serInStr[i] = 0;  // say we've used the string (not needed really)
    digitalWrite(ledPin,LOW); // show we're done
 void rpm_fun()
   //Each rotation, this interrupt function is run twice
//read a string from the serial and store it in an array
//you must supply the str array variable
//returns number of bytes read, or zero if fail
uint8_t readCommand(byte *str)
    uint8_t b,i;
    if( ! Serial.available() ) return 0;  // wait for serial

    b =;
    if( b != CMD_START_BYTE )         // check to see we're at the start
        return 0;
#ifdef DEBUG

    str[0] = b;
    i = 100;
    while( Serial.available() < 3 ) {   // wait for the rest
        if( i-- == 0 ) return 0;        // get out if takes too long
    for( i=1; i<4; i++)
        str[i] =;       // fill it up
#ifdef DEBUG

    uint8_t sendlen = str[2];
#ifdef DEBUG
    Serial.print("cmdlen:");  Serial.println( sendlen, DEC);
    if( sendlen == 0 ) return 0;
    i = 100;
    while( Serial.available() < sendlen ) {  // wait for the final part
        delay(1); if( i-- == 0 ) return 0;
    for( i=4; i<4+sendlen; i++ ) 
        str[i] =;       // fill it up

#ifdef DEBUG
    Serial.println("got all");
    return 4+sendlen;

Alright, i tested rpm counting and it just comes up with garbled stuff in the terminal

Simple stuff first... is your baud rate set correctly? You set it first to 9600 and then a few lines later to 19200. If you don't have the terminal set to the same value you'll sure get junk displayed...

alright, deleted the first one, set the terminal correctly, and it still does nothing. No garbled text either

It should be said that the extent of my programming experience is with the basic stamps, and that was when I was like 8, 9 years ago

Never used BlinkM gear, so can't comment on that stuff at all, but you should be seeing at least the output from this line:

Serial.println("BlinkMCommander ready");

How is everything wired up? Have you got a schematic?

Never used BlinkM gear, so can't comment on that stuff at all, but you should be seeing at least the output from this line:

Serial.println("BlinkMCommander ready");

How is everything wired up? Have you got a schematic?

I see "linkMColCmer ready"

Also, the circuit is just a reed switch in between 5v and pin 2, and the blinkm plugged in to analog pins 5, 4, 3, and 2. (when i install it into the bike, it will be 5, 4, and gnd, but i need to get my lenses first)