Skip to content

Commit ba5ab31

Browse files
committed
Glow 4 times slowly
1 parent 0a7cacd commit ba5ab31

File tree

1 file changed

+28
-25
lines changed
  • customer_app/sdk_app_tflite/sdk_app_tflite

1 file changed

+28
-25
lines changed

customer_app/sdk_app_tflite/sdk_app_tflite/demo.c

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -60,31 +60,34 @@ static void glow(char *buf, int len, int argc, char **argv) {
6060
rc = bl_pwm_start(PWM_CHANNEL);
6161
assert(rc == 0);
6262

63-
// Based on input values from 0 to 2 * Pi (stepping by 0.1)...
64-
for (float input = 0; input < kXrange; input += 0.1) { // kXrange is 2 * Pi: 6.283
65-
// Infer the output value with the TensorFlow Model (Sine Wave)
66-
float output = run_inference(input);
67-
68-
// Output value has range -1 to 1.
69-
// We square the output value to produce range 0 to 1.
70-
float output_squared = output * output;
71-
72-
// Set the brightness (Duty Cycle) of the PWM LED to the
73-
// output value squared, scaled to 100%
74-
rc = bl_pwm_set_duty(
75-
PWM_CHANNEL, // PWM Channel (1)
76-
(1 - output_squared) * 100 // Duty Cycle (0% to 100%)
77-
);
78-
assert(rc == 0);
79-
80-
// We flip the brightness (1 - output squared) because...
81-
// Duty Cycle = 0% means 100% brightness
82-
// Duty Cycle = 100% means 0% brightness
83-
84-
// Sleep 100 milliseconds
85-
time_delay( // Sleep by number of ticks (from NimBLE Porting Layer)
86-
time_ms_to_ticks32(100) // Convert 100 milliseconds to ticks (from NimBLE Porting Layer)
87-
);
63+
// Repeat 4 times...
64+
for (int i = 0; i < 4; i++) {
65+
// With input values from 0 to 2 * Pi (stepping by 0.05)...
66+
for (float input = 0; input < kXrange; input += 0.05) { // kXrange is 2 * Pi: 6.283
67+
// Infer the output value with the TensorFlow Model (Sine Wave)
68+
float output = run_inference(input);
69+
70+
// Output value has range -1 to 1.
71+
// We square the output value to produce range 0 to 1.
72+
float output_squared = output * output;
73+
74+
// Set the brightness (Duty Cycle) of the PWM LED to the
75+
// output value squared, scaled to 100%
76+
rc = bl_pwm_set_duty(
77+
PWM_CHANNEL, // PWM Channel (1)
78+
(1 - output_squared) * 100 // Duty Cycle (0% to 100%)
79+
);
80+
assert(rc == 0);
81+
82+
// We flip the brightness (1 - output squared) because...
83+
// Duty Cycle = 0% means 100% brightness
84+
// Duty Cycle = 100% means 0% brightness
85+
86+
// Sleep 100 milliseconds
87+
time_delay( // Sleep by number of ticks (from NimBLE Porting Layer)
88+
time_ms_to_ticks32(100) // Convert 100 milliseconds to ticks (from NimBLE Porting Layer)
89+
);
90+
}
8891
}
8992

9093
// Stop the PWM, which will stop blinking the LED

0 commit comments

Comments
 (0)