Skip to content

Commit b4eb8e1

Browse files
committed
[example][hello world] 适配RTduino
1 parent 2283ed3 commit b4eb8e1

File tree

4 files changed

+4
-71
lines changed

4 files changed

+4
-71
lines changed

examples/hello_world/arduino_main.cpp

Lines changed: 0 additions & 20 deletions
This file was deleted.

examples/hello_world/arduino_output_handler.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,8 @@ limitations under the License.
2323
// The pin of the Arduino's built-in LED
2424
int led = LED_BUILTIN;
2525

26-
// Track whether the function has run at least once
27-
bool initialized = false;
28-
2926
// Animates a dot across the screen to represent the current x and y values
3027
void HandleOutput(float x_value, float y_value) {
31-
// Do this only once
32-
if (!initialized) {
33-
// Set the LED pin to output
34-
pinMode(led, OUTPUT);
35-
initialized = true;
36-
}
37-
3828
// Calculate the brightness of the LED such that y=-1 is fully off
3929
// and y=1 is fully on. The LED's brightness can range from 0-255.
4030
int brightness = (int)(127.5f * (y_value + 1));

examples/hello_world/hello_world.ino renamed to examples/hello_world/hello_world.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@ limitations under the License.
1414
==============================================================================*/
1515

1616
#include <TensorFlowLite.h>
17-
17+
#include <RTduino.h>
1818
#include "constants.h"
19-
#include "main_functions.h"
2019
#include "model.h"
2120
#include "output_handler.h"
2221
#include "tensorflow/lite/micro/all_ops_resolver.h"
@@ -39,7 +38,7 @@ alignas(16) uint8_t tensor_arena[kTensorArenaSize];
3938
} // namespace
4039

4140
// The name of this function is important for Arduino compatibility.
42-
void setup() {
41+
static void _sine_setup(void) {
4342
tflite::InitializeTarget();
4443

4544
// Map the model into a usable data structure. This doesn't involve any
@@ -78,7 +77,7 @@ void setup() {
7877
}
7978

8079
// The name of this function is important for Arduino compatibility.
81-
void loop() {
80+
static void _sine_loop(void) {
8281
// Calculate an x value to feed into the model. We compare the current
8382
// inference_count to the number of inferences per cycle to determine
8483
// our position within the range of possible x values the model was
@@ -113,3 +112,4 @@ void loop() {
113112
inference_count += 1;
114113
if (inference_count >= kInferencesPerCycle) inference_count = 0;
115114
}
115+
RTDUINO_SKETCH_LOADER("tfsine", _sine_setup, _sine_loop);

examples/hello_world/main_functions.h

Lines changed: 0 additions & 37 deletions
This file was deleted.

0 commit comments

Comments
 (0)