Go Down

Topic: [SOLVED] Issues with Arduino 1.0 (Read 585 times) previous topic - next topic

kustom

Feb 25, 2012, 03:00 pm Last Edit: Feb 25, 2012, 03:32 pm by kustom Reason: 1
At first I thought there was something wrong with my code, but then I've tried to compile and upload it using Arduino 0022 and it works. Here is my problem:

I'm breaking my code down to libraries so that it's easier to read. Right now I'm on shifting in.

So, here are relevant parts of code:

main:

Code: [Select]
#include <ShiftRegisterDataCollect.h>


//number of shift registers
#define NUMBER_OF_SHIFT_REGISTERS 3

//shift register pins
#define CLOCK_PIN 7
#define LATCH_PIN 8
#define DATA_PIN 9


//for loop
int i = 0;

//Define variables to hold the data for each shift register.
byte switchVar[NUMBER_OF_SHIFT_REGISTERS] = {0};


...


ShiftRegisterDataCollect shiftData(LATCH_PIN, CLOCK_PIN, DATA_PIN);


void setup() {
 //start serial
 Serial.begin(9600);
 
 ...

}

void loop() {
 
 shiftData.latchPinFunc();  
 for (i=0; i<NUMBER_OF_SHIFT_REGISTERS; i++)  {
   
   switchVar[i] = shiftData.shiftInFunc();
   Serial.println(switchVar[i], BIN);
   
   
 }
 
 Serial.print("-------------\n");
 delay(200);
 
}


header:

Code: [Select]
#ifndef ShiftRegisterDataCollect_h
#define ShiftRegisterDataCollect_h

#include "WProgram.h"



class ShiftRegisterDataCollect  {

   public:
       ShiftRegisterDataCollect(int latchPin, int clockPin, int dataPin);
       byte shiftInFunc();
       void latchPinFunc();

   private:
       int _latchPin, _dataPin, _clockPin;


};


#endif


.cpp:

Code: [Select]
#include "WProgram.h"
#include "ShiftRegisterDataCollect.h"

ShiftRegisterDataCollect::ShiftRegisterDataCollect(int latchPin, int clockPin, int dataPin) {

  pinMode(latchPin, OUTPUT);
  pinMode(clockPin, OUTPUT);
  pinMode(dataPin, INPUT);


 _latchPin = latchPin;
 _clockPin = clockPin;
 _dataPin = dataPin;
}

byte ShiftRegisterDataCollect::shiftInFunc() {

   int i;
   int temp = 0;
   int pinState;
   byte myDataIn = 0;

 for (i=7; i>=0; i--)  {

   digitalWrite(_clockPin, 0);
   delayMicroseconds(2);
   temp = digitalRead(_dataPin);

   if (temp) {
     pinState = 1;
     //set the bit to 0 no matter what
     myDataIn = myDataIn | (1 << i);
   }

   else {
     //turn it off -- only necessary for debuging
    //print statement since myDataIn starts as 0
     pinState = 0;
   }

   digitalWrite(_clockPin, 1);
 }

 return myDataIn;
}

...


Errors I'm getting using v1.0:



The code compiles and runs just fine using 0022 so I'm guessing it's some weird bug or something in 1.0.

James C4S

You haven't read the release notes for 1.0   

WProgram.h is now Arduino.h
Capacitor Expert By Day, Enginerd by night.  ||  Personal Blog: www.baldengineer.com  || Electronics Tutorials for Beginners:  www.addohms.com

spycatcher2k

Add a file to C:\{path to arduino}\arduino-1.0\hardware\arduino\cores\arduino called WProgram.h - edit it and add the line : #include <Arduino.h>

That should clear that up for you.
Drew.
http://www.uk-pcb.co.uk - My UK Based PCB Fab & Assembly Company
Design work undertaken
SMD & Thru-Hole assembly

kustom

Ah okay. It works just fine now. Thanks.

Go Up