Skip to content

Commit

Permalink
Clean-up examples
Browse files Browse the repository at this point in the history
- do not call constructor in setup()
- format using Arduino IDE v2
- rename example code to new name scheme:
  - `test_` prefix only for sensor testing code not for usage examples
  - sensor name prefix if example refers to 3rd party sensor
  - drop `lm_` prefix
  • Loading branch information
lmoellendorf committed Oct 29, 2023
1 parent c93e164 commit 49e532e
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@
#include <LmMeHtIrSeekerV2.h>
#include <LmEncoderOnBoardMotor.h>

MeHtIrSeekerV2 seeker;
MeHtIrSeekerV2 seeker = MeHtIrSeekerV2(PORT_6, MeHtIrSeekerV2::AC);
EncoderOnBoardMotor motor_l = EncoderOnBoardMotor(SLOT2);
EncoderOnBoardMotor motor_r = EncoderOnBoardMotor(SLOT1);

void setup() {
seeker = MeHtIrSeekerV2(PORT_6, MeHtIrSeekerV2::AC);
}

void loop() {
Expand Down
File renamed without changes.
28 changes: 13 additions & 15 deletions examples/rgb_led_ring/rgb_led_ring.ino
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,19 @@
MeRGBLed led_ring = MeRGBLed(0, 12);
int i = 0;

void setup()
{
led_ring.setpin(44);
void setup() {
led_ring.setpin(44);
}

void loop()
{
int led;
/* 0 <= led <= 11 */
led = (i % 12);
/* 1 <= led <= 12 */
led++;
led_ring.setColor(0, 0, 0, 0);
led_ring.setColor(led, 255, 0, 0);
led_ring.show();
delay(100);
i++;
void loop() {
int led;
/* 0 <= led <= 11 */
led = (i % 12);
/* 1 <= led <= 12 */
led++;
led_ring.setColor(0, 0, 0, 0);
led_ring.setColor(led, 255, 0, 0);
led_ring.show();
delay(100);
i++;
}
31 changes: 13 additions & 18 deletions examples/rgb_led_ring2/rgb_led_ring2.ino
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,24 @@

MeRGBLed led_ring = MeRGBLed(0, 12);

void setup()
{
led_ring.setpin(44);
void setup() {
led_ring.setpin(44);
}

uint8_t dim(double n_led, double led)
{
return 255. * (-n_led * pow(led, 2) + pow(n_led,
2) * led) / (-n_led * pow(n_led / 2., 2) + pow(n_led, 2) * n_led / 2.);
uint8_t dim(double n_led, double led) {
return 255. * (-n_led * pow(led, 2) + pow(n_led, 2) * led) / (-n_led * pow(n_led / 2., 2) + pow(n_led, 2) * n_led / 2.);
}

void loop()
{
int n_led = 12;
void loop() {
int n_led = 12;

for (int i = 0; i < 12; i++) {
led_ring.setColor(0, 0, 0, 0) ;
for (int i = 0; i < 12; i++) {
led_ring.setColor(0, 0, 0, 0);

for (int j = 0; j < n_led; j++)
led_ring.setColor(((i + j) % 12) + 1, dim(n_led, j), dim(n_led,
(j + n_led / 2) % n_led), dim(n_led, (j + n_led / 4) % n_led)) ;
for (int j = 0; j < n_led; j++)
led_ring.setColor(((i + j) % 12) + 1, dim(n_led, j), dim(n_led, (j + n_led / 2) % n_led), dim(n_led, (j + n_led / 4) % n_led));

led_ring.show();
delay(100);
}
led_ring.show();
delay(100);
}
}
50 changes: 24 additions & 26 deletions examples/simple_gyro_led/simple_gyro_led.ino
Original file line number Diff line number Diff line change
Expand Up @@ -17,35 +17,33 @@ double x, y, z;
/* store LED color intensity values */
int r, g, b;

void setup()
{
/* setup and start I2C communication */
gyro.begin();
/* set Arduino pin where LED ring is connected to */
led_ring.setpin(44);
void setup() {
/* setup and start I2C communication */
gyro.begin();
/* set Arduino pin where LED ring is connected to */
led_ring.setpin(44);
}

void loop()
{
/* read new set of values from sensor */
gyro.update();
void loop() {
/* read new set of values from sensor */
gyro.update();

/* get x axis value : -90 to 90 degree */
x = gyro.getAngleX();
/* get y axis value : -90 to 90 degree */
y = gyro.getAngleY();
/* get z axis value : -180 to 180 degree */
z = gyro.getAngleZ();
/* get x axis value : -90 to 90 degree */
x = gyro.getAngleX();
/* get y axis value : -90 to 90 degree */
y = gyro.getAngleY();
/* get z axis value : -180 to 180 degree */
z = gyro.getAngleZ();

/* convert x value to R value: 0 to 255 */
r = ((x + 90) / 180) * 255;
/* convert y value to G value: 0 to 255 */
g = ((y + 90) / 180) * 255;
/* convert z value to B value: 0 to 255 */
b = ((z + 180) / 360) * 255;
/* convert x value to R value: 0 to 255 */
r = ((x + 90) / 180) * 255;
/* convert y value to G value: 0 to 255 */
g = ((y + 90) / 180) * 255;
/* convert z value to B value: 0 to 255 */
b = ((z + 180) / 360) * 255;

/* set RGB color values */
led_ring.setColor(0, r, g, b) ;
/* apply RGB color values */
led_ring.show();
/* set RGB color values */
led_ring.setColor(0, r, g, b);
/* apply RGB color values */
led_ring.show();
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include <MeAuriga.h>
#include <LmMeHtIrSeekerV2.h>

MeHtIrSeekerV2 seeker;
MeHtIrSeekerV2 seeker = MeHtIrSeekerV2(PORT_6, MeHtIrSeekerV2::AC);

void getDeviceInfo(void) {
char fw_str[9] = { 0 };
Expand Down Expand Up @@ -31,7 +31,6 @@ void getDeviceInfo(void) {
}

void setup() {
seeker = MeHtIrSeekerV2(PORT_7, MeHtIrSeekerV2::AC);
Serial.begin(9600);
/* wait untill the sensor is fully powered */
delay(1);
Expand Down
File renamed without changes.
File renamed without changes.

0 comments on commit 49e532e

Please sign in to comment.