Pages: [1]   Go Down
Author Topic: [SOLVED] Issues with Arduino 1.0  (Read 512 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Sr. Member
****
Karma: 1
Posts: 251
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
#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:
#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:
#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.
« Last Edit: February 25, 2012, 09:32:29 am by kustom » Logged

Austin, TX
Offline Offline
Faraday Member
**
Karma: 71
Posts: 6119
Baldengineer
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

You haven't read the release notes for 1.0   

WProgram.h is now Arduino.h
Logged

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

Scotland
Online Online
Edison Member
*
Karma: 24
Posts: 1227
Have you had your Arduino fix today?
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Drew.
http://www.uk-pcb.co.uk - My UK Based PCB Fab & Assembly Company
Design work undertaken
SMD & Thru-Hole assembly

Offline Offline
Sr. Member
****
Karma: 1
Posts: 251
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ah okay. It works just fine now. Thanks.
Logged

Pages: [1]   Go Up
Jump to: