SofaPirate / Plaquette

Object-oriented Arduino library for creative physical computing

Home Page:https://sofapirate.github.io/Plaquette/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Create a bridge / callback unit to easily transform anything into a Node

sofian opened this issue · comments

Could look like this:

MyAnalogSensor photo;
MyAnalogActuator motor;
MyDigitalSensor button;
MyDigitalActuator relay;

AnalogCallback photoCallback(readPhoto);
AnalogCallback motorCallback(readMotor, writeMotor);
DigitalCallback buttonCallback(readButton);
DigitalCallback relayCallback(readRelay, writeRelay);

float readPhoto() {
  return mapTo01(sensor.read(), 0, 1023);
}

float readMotor() {
  return motor.currentValue();
}

float writeMotor(float value) {
  motor.writeRaw((int)mapFrom01(value, 0, 255));
  return motor.currentValue(); // *** this seems superfluous ... perhaps there is a better way
}

bool readButton() {
  return button.isPressed();
}

...

void step() {
  if (buttonCallback) {
    photoCallback >> motorCallback;
    relayCallback.off();
  }
  else
    relayCallback.on();
}