Show Posts
Pages: [1]
1  Using Arduino / Programming Questions / Re: bit shifting on: May 02, 2013, 12:15:25 pm
You can try this one:

byte testA=B0110;
byte testB=B1011;

void setup(){
  testB=testA<<4 | testB;
  Serial.begin(9600);
  Serial.println(testB,BIN);
}
void loop(){

}

the 2nd parameter of Serial.print can help a lot sometimes smiley
2  Using Arduino / Programming Questions / Re: Conflicting library files on: May 02, 2013, 11:52:50 am
Just figured out a way that seemingly solves the problem:


    libraries  
      +Foo
        -Foo.h
        +extra
          -Helper.h  
      +Bar
        -Bar.h
        +extra
          -Helper.h  
      +Helper
        -Helper.h


In this way, `Helper.h` in `Foo` and `Bar` would be invisible to sketches, and I can write `#include "extra/Helper.h"` in `Foo` and `Bar` respectively to include the desired files.

With more tests, it turned out that this method does not solve the problem, but hiding it a lever deeper. So if you include Foo and Helper, Bar and Helper, or Foo and Bar, only one version of Helper.h will be included.
3  Using Arduino / Programming Questions / Conflicting library files on: May 02, 2013, 11:30:35 am
I'm writing libraries and having the library folder structure like this:

libraries
  -Foo
    -Foo.h
    -Helper.h
  -Bar
    -Bar.h
    -Helper.h
  -Helper
    -Helper.h

I figured that if I write "#include <Helper.h>" in my sketch, it'll be impossible to control which "Helper.h" is included.
"Helper.h" is included in other libraries, mostly for the concern that it's easier for end user to get the library running, and I have better control over its configurations(Some libraries need to have their source code modified to be configured).

So is there a way to hide the "Helper.h" in Foo and Bar, so if I write "#include <Helper.h>", only the one from Helper folder will be included?
4  Using Arduino / Programming Questions / Re: Creating libraries in Arduino sketch folder on: January 19, 2013, 11:11:53 am
Interesting...
The example is just for showing my problem regarding undeclared functions, so it doesn't have real purpose. However I never thought about the potential problem between constructor and hardware. Thank you for the extra knowledge! smiley So what problems can there be?
5  Using Arduino / Programming Questions / Re: Creating libraries in Arduino sketch folder on: January 19, 2013, 07:12:45 am
Thanks @pYro_65, just figured it out after getting stuck somewhere else for a couple of hours smiley-grin
I saw someone using the following in his library:
Code:
#if ARDUINO >= 100
#include "Arduino.h"
#else
#include "WProgram.h"
#endif
Which may be a even better solution.
But changing the library name is pretty bad for backwards compatibility though
6  Using Arduino / Programming Questions / Creating libraries in Arduino sketch folder on: January 19, 2013, 05:38:15 am
I'm creating a few classes for a project, which seems so specific that I don't want to keep in the libraries folder. They're mostly working, however, if I want to call any Arduino functions or consts, it will throw errors "is not declared in this scope".

sketch:

Code:
#include "MyClass.h"
void setup(){
}
void loop(){
}
MyClass.h

Code:
class MyClass{
    public:
        MyClass(int inp);
        int myFun();
};
MyClass.cpp

Code:
#include "MyClass.h"
#include <WProgram.h>

MyClass::MyClass(int inp){
    pinMode(13,HIGH);

}
error:

MyClass.cpp: 'HIGH','pinMode' is not declared in this scope.

It wouldn't happen if I put the libraries in libraries folder though. Wondering if there's a way to include arduino functions into sketch folder libraries?
7  Forum 2005-2010 (read only) / Interfacing / IR receiver+IR LED as approaching sensor problem on: April 02, 2010, 05:43:37 am
Hey! I'm trying to make a approaching sensor, using exactly the description of "Simple IR Distance Sensor Tutorial"( You can search for this title in arduino.cc, it should be the second result)
except that I'm using a different IR sensor, probably GP18A38AC (according to the shape  smiley-razz) . Its pin-sequence should be GND,5V,"gap",OUT.

As long as I have the LED connected, it will show 0 in serial monitor(means it detects something), no matter how I block them from one another. The funny thing is, if I change the LED to a wire, it will also show 0. If I disconnect the LED or connect its input to an unused pin or a 5v pin, the serial monitor will show 1. I'm wondering what's the problem, as the sensor and LED only have their GND in common. And, of course, my approaching sensor is not working  smiley-sad
Pages: [1]