Register / Login | Desktop view |
Filename | 75FD1AFE-42D2-4C5E-81DF-F6D7CCB7FB8E.png |
Description | wiring |
Filesize | 15 Kbytes |
Downloaded | 45178 time(s) |
Download |
Filename | 3D135D18-4C84-45FF-836C-29AD62B8C690.jpeg |
Description | photo |
Filesize | 187 Kbytes |
Downloaded | 45480 time(s) |
Download |
#include <DfRobotInputAbstraction.h>
IoAbstractionRef dfRobotKeys = inputFromDfRobotShield();
switches.initialise(dfRobotKeys, false); // df robot is always false for 2nd parameter.
const PROGMEM DfRobotAnalogRanges myRanges { 0.0488F, 0.2441F, 0.4394F, 0.6347F, 0.8300F}; // right, up, down, left, select
DfRobotInputAbstraction dfRobotIo = DfRobotInputAbstraction(&myRanges, pin, device);
IoAbstractionRef dfRobotKeys = &dfRobotIo;
Arduino : 1.8.13 (Windows 10), Carte : "WiFi Kit 32, Disabled, 240MHz (WiFi/BT), 921600, None"
exit status 1
'device' was not declared in this scope
#include "tcmenu_menu.h"
// Debut AMA button
#include <DfRobotInputAbstraction.h>
// IoAbstractionRef dfRobotKeys = inputFromDfRobotShield();
const PROGMEM DfRobotAnalogRanges myRanges { 0.0488F, 0.2441F, 0.4394F, 0.6347F, 0.8300F}; // right, up, down, left, select
DfRobotInputAbstraction dfRobotIo = DfRobotInputAbstraction(&myRanges, 35, device);
IoAbstractionRef dfRobotKeys = &dfRobotIo;
void logKeyPressed(const char* whichKey, bool heldDown) {
Serial.print("Key ");
Serial.print(whichKey);
Serial.println(heldDown ? " Held" : " Pressed");
}
/**
* Along with using functions to receive callbacks when a button is pressed, we can
* also use a class that implements the SwitchListener interface. Here is an example
* of implementing that interface. You have both choices, function callback or
* interface implementation.
*/
class MyKeyListener : public SwitchListener {
private:
const char* whatKey;
public:
// This is the constructor where we configure our instance
MyKeyListener(const char* what) {
whatKey = what;
}
// when a key is pressed, this is called
void onPressed(pinid_t /*pin*/, bool held) override {
logKeyPressed(whatKey, held);
}
// when a key is released this is called.
void onReleased(pinid_t /*pin*/, bool held) override {
Serial.print("Release ");
logKeyPressed(whatKey, held);
}
};
MyKeyListener selectKeyListener("SELECT");
// Fin AMA button
void setup() {
setupMenu();
// Début AMA cycle
// taskManager.scheduleFixedRate(1000, toggle);
// Fin AMA
// Début AMA button
// start up the serial port in a way compatible with 32 bit boards.
while(!Serial);
Serial.begin(115200);
// initialise the switches component with the DfRobot shield as the input method.
switches.initialise(dfRobotKeys, false); // df robot is always false for 2nd parameter.
// now we add the switches, each one just logs the key press, the last parameter to addSwitch
// is the repeat frequency is optional, when not set it implies not repeating.
switches.addSwitch(DF_KEY_DOWN, [](pinid_t /*pin*/, bool held) { logKeyPressed("DOWN", held);}, 20);
switches.addSwitch(DF_KEY_UP, [](pinid_t /*pin*/, bool held) { logKeyPressed("UP", held);}, 20);
switches.addSwitch(DF_KEY_LEFT, [](pinid_t /*pin*/, bool held) { logKeyPressed("LEFT", held);}, 20);
switches.addSwitch(DF_KEY_RIGHT, [](pinid_t /*pin*/, bool held) { logKeyPressed("RIGHT", held);}, 20);
switches.onRelease(DF_KEY_RIGHT, [](pinid_t /*pin*/, bool) { Serial.println("RIGHT has been released");});
switches.addSwitchListener(DF_KEY_SELECT, &selectKeyListener);
// Fin AMA
}
void loop() {
taskManager.runLoop();
}
void CALLBACK_FUNCTION onSaveSettings(int id) {
// TODO - your menu change code
}
void CALLBACK_FUNCTION onStartToasting(int id) {
// TODO - your menu change code
}
void CALLBACK_FUNCTION onNameChanged(int id) {
// TODO - your menu change code
}
// Début AMA cycle
void toggle() {
if (menuToasterPower.getCurrentValue() == 9)
{
menuToasterPower.setCurrentValue(3);
}
else
{
menuToasterPower.setCurrentValue(9);
}
}
// Fin AMA
Filename | Capture.PNG |
Description | Analog pin wired on pin 35 |
Filesize | 536 Kbytes |
Downloaded | 45046 time(s) |
Download |
#include <AnalogDeviceAbstraction.h>
const PROGMEM DfRobotAnalogRanges myRanges { 0.0488F, 0.2441F, 0.4394F, 0.6347F, 0.8300F}; // right, up, down, left, select
const PROGMEM DfRobotAnalogRanges myRanges { 0.7675F, 0.2200F, 0.4993F, 0.0001F, 0.9999F}; // right, up, down, left, select
const PROGMEM DfRobotAnalogRanges myRanges { 0.7030F, 0.1666F, 0.4363F, 0.0001F}; // right, up, down, left, select
Select button seems no effect on voltage .... seems a device fauft. Ok i will try with 4 buttons only.
(I have deleted the 5th term as the "select button" doesn't change voltage measured.)
davetcc wrote:
Leave it in and set it to .9999, otherwise the value may be somewhat undefined and cause problems.
davetcc wrote:
Got it now, looking at the code, you need to define them in order of voltage, because it works like
button 0 > 0 and < button0 threshold
button 1 > button0 threshold and < button1 threshold
So you can treat the buttons as 0, 1, 2, 3, 4 without considering if they are left right etc. In your case button 0 will be the one with the lowest value etc.
Hope that makes sense.
Filename | Capture2.PNG |
Description | No description given |
Filesize | 10 Kbytes |
Downloaded | 44719 time(s) |
Download |
Filename | Capture.PNG |
Description | No description given |
Filesize | 136 Kbytes |
Downloaded | 43909 time(s) |
Download |
davetcc wrote:In the code generator, you would set IoExpander ref to your instance of IoExpanderRef.
And then each of the buttons would be configured as 0..3. Where the pin with the lowest analog value would be 0 and so on.