Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions examples/esp8266/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#if defined(ARDUINO_ARCH_ESP8266)
#include <Ticker.h>
#else
#include <TimerOne.h>
#endif
#include <Wire.h>
#include <MultiFuncShield.h>

void setup() {
// put your setup code here, to run once:

// Timer1.initialize();
MFS.initialize(); // initialize multi-function shield library

MFS.write("Hi");
delay(2000);
MFS.write(-273);
delay(2000);
MFS.write(3.141, 2); // display to 2 decimal places.
delay(2000);
}

int counter=0;
byte ended = false;

void loop() {
// put your main code here, to run repeatedly:

if (counter < 200)
{
MFS.write((int)counter);
counter++;
}
else if (!ended)
{
ended = true;
MFS.write("End");
MFS.blinkDisplay(DIGIT_ALL, ON);
}
delay(50);
}
7 changes: 6 additions & 1 deletion examples/tests/main.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
#if defined(ARDUINO_ARCH_ESP8266)
#include <Ticker.h>
#else
#include <TimerOne.h>
#endif

#include <Wire.h>
#include <EEPROMex.h>
#include "MultiFuncShield.h"
#include <MultiFuncShield.h>

#define TIMER_VALUE_MAX 99

Expand Down
30 changes: 24 additions & 6 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,30 @@ lib_dir = ./

[env]
framework = arduino
platform = atmelavr
monitor_speed = 115200
build_flags =
-D CORE_DEBUG_LEVEL=0

[common]
framework = ${env.framework}
monitor_speed = ${env.monitor_speed}
lib_deps = ${env.lib_deps}
build_flags = ${env.build_flags}

[arduino_common]
platform = atmelavr
framework = ${env.framework}
monitor_speed = ${env.monitor_speed}
build_flags = ${env.build_flags}
lib_deps =
TimerOne @ 1.1.1
Servo @ 1.2.1
EEPROMEx

[arduino_common]
platform = ${env.platform}
framework = ${env.framework}
monitor_speed = ${env.monitor_speed}
lib_deps = ${env.lib_deps}
[esp8266_common]
extends = common
platform = espressif8266
board = d1_mini_pro

[env:uno]
board = uno
Expand All @@ -43,4 +54,11 @@ board = ATmega328P
extends = arduino_common
build_src_filter = -<*> +<tests/>

[env:wemosd1]
extends = esp8266_common
board = d1_mini
build_src_filter = -<*> +<esp8266/>




17 changes: 15 additions & 2 deletions src/MultiFuncShield.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,19 @@ void MultiFuncShield::initShield()
}

// ----------------------------------------------------------------------------------------------------
#if defined(ARDUINO_ARCH_ESP8266)
void MultiFuncShield::initialize(Ticker *timer1Instance)
#else
void MultiFuncShield::initialize(TimerOne *timer1Instance)
#endif
{
initShield();

timer1 = timer1Instance;
#if defined(ARDUINO_ARCH_ESP8266)
timer1->attach(1000,isrWrapper); // effectively, 1000 times per second
#else
timer1->attachInterrupt(isrWrapper, 1000); // effectively, 1000 times per second
#endif
}


Expand Down Expand Up @@ -338,7 +345,7 @@ byte MultiFuncShield::getButton ()
button_read_pos = 0;
}
}

return button;
}

Expand Down Expand Up @@ -1371,4 +1378,10 @@ void WriteValueToSegment(byte Segment, byte Value)
break;
}
}
#else
/* Write a value to one of the 4 digits of the display */
void WriteValueToSegment(byte Segment, byte Value)
{

}
#endif
58 changes: 52 additions & 6 deletions src/MultiFuncShield.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#include <TimerOne.h>

#ifndef MultiFuncShield_h_
#define MultiFuncShield_h_

Expand All @@ -8,9 +6,46 @@

#include "Arduino.h"

#if defined(ARDUINO_ARCH_ESP32)

#elif defined(ARDUINO_ARCH_ESP8266)
#include <Ticker.h>
#else
#include <TimerOne.h>
#endif

#define ON 1
#define OFF 0

#if defined(ARDUINO_ARCH_ESP8266)
#define LED_1_PIN D5
#define LED_2_PIN D6
#define LED_3_PIN D7
#define LED_4_PIN D8
#define POT_PIN RX
#define BEEPER_PIN D1
#define BUTTON_1_PIN A0
#define BUTTON_2_PIN A0
#define BUTTON_3_PIN A0
#define LATCH_PIN D2
#define CLK_PIN D5
#define DATA_PIN D6
#define LM35_PIN A0

#define DIGIT_1 1
#define DIGIT_2 2
#define DIGIT_3 4
#define DIGIT_4 8
#define DIGIT_ALL 15

#define LED_1 1
#define LED_2 2
#define LED_3 4
#define LED_4 8
#define LED_ALL 15

#else

#define LED_1_PIN 13
#define LED_2_PIN 12
#define LED_3_PIN 11
Expand All @@ -36,6 +71,7 @@
#define LED_3 4
#define LED_4 8
#define LED_ALL 15
#endif

// button state indicators
#define BUTTON_PRESSED_IND (0 << 6)
Expand Down Expand Up @@ -71,8 +107,12 @@ class MultiFuncShield
void (*userInterrupt)() = NULL;

// Initializes this instance using a TimerOne instance. A 1khz interrupt is attached.
void initialize(TimerOne *timer1);

#if defined(ARDUINO_ARCH_ESP8266)
void initialize(Ticker *timer1Instance);
#else
void initialize(TimerOne *timer1Instance);
#endif

// Initializes this instance, but interrupt based features are not available.
void initialize();

Expand Down Expand Up @@ -165,10 +205,16 @@ class MultiFuncShield

// Gets the temperature reading in 1 tenths of a centigrade.
int getLM35Data();
private:

private:
void initShield();

#if defined(ARDUINO_ARCH_ESP8266)
Ticker *timer1;
#else
TimerOne *timer1;
#endif

volatile byte timerReadInProgress = 0;
volatile byte timerWriteInProgress = 0;

Expand Down