Interfacing from a library to a program


yesterday wrote library reads input data given pin, transferring 1 (or more) command(s), , (should) give program wrote. question is: how can make library invoke method in program? there reference 'static' can put in front of method in library or else?

my library in attachments (sry it's written in german ;) ) .

here program:

#include <steuerung.h>

steuerung s(a0, a1, a2);

void setup() {
  serial.begin(9600);
}

void loop() {
  s.looop();
  delay(100);
}

void buttonevent(int but, boolean pressed) {
  serial.println(string(but)+"\t"+string(pressed));
}

hoping knows how solve problem! :)

quote
now question is: how can make library invoke method in program?
the library knows nothing sketch using except tell it. library needs have methods register callbacks specific events. register functions in sketch library should called when event happens.

code: [select]
steuerung::steuerung(int x, int y, int taster) {
  pinmode(x, input);
  pinmode(y, input);
  pinmode(taster, input);
 
  pinx = x;
  piny = y;
  pintast = taster;
 
  normx = analogread(x);
  normy = analogread(y);
}

just every possibly done wrong in constructor being done wrong here.

the hardware not ready have mode of pins set. analog pins read only. pinmode() function affects digital pins.

reading pins not ready not useful.

code: [select]
void steuerung::looop() {
good method names consist of noun , verb (what do, what), digitalread() reads digital pin. name next useless. tells nothing method does.



Arduino Forum > Using Arduino > Programming Questions > Interfacing from a library to a program


arduino

Comments