Hi there, Such a simple thing like LED’s Why wouldn’t they be the same for both makes no-Sense to me
but I digress,
So what’s in a Name?
pinMode(LED_RED, OUTPUT); //1.1.1
pinMode(LED_GREEN, OUTPUT);
pinMode(LED_BLUE, OUTPUT);
/*****************************************************************************/
// IMU Interrupt Example for XIAO BLE Sense
// This example shows how to configure LMSD6S3TR-C on XIAO BLE SENSE to interrupt
// on INT1 after a "Double Tap" was recognized.
// Additionally, the device goes into System OFF state, after 3 interrupts were
// received. Another "Double Tap" will wake up the device again.
//
// Original by chuck
//poatched and toasted by pjg
// LEDs 2.9.2
// ----
//#define PIN_LED (12u)
//#define LED_BUILTIN PIN_LED
//#define LEDR (12u)
//#define LEDG (13u)
//#define LEDB (14u)
//#define LED_PWR (12u)
// LEDs 1.1.1
// 26, // D11 is P0.26 (LED RED)
// 6, // D12 is P0.06 (LED BLUE)
// 30, // D13 is P0.30 (LED GREEN)
// 14, // D14 is P0.14 (READ_BAT)
// this is what works.. pinMode(LED_RED, OUTPUT); //1.1.1
// pinMode(LED_GREEN, OUTPUT);
// pinMode(LED_BLUE, OUTPUT);
/*******************************************************************************/
#include "LSM6DS3.h"
#include "Wire.h"
#include <U8x8lib.h>
LSM6DS3 myIMU(I2C_MODE, 0x6A); // IMU
#define int1Pin PIN_LSM6DS3TR_C_INT1
U8X8_SSD1306_128X64_NONAME_HW_I2C u8x8(/* clock=*/ PIN_WIRE_SCL, /* data=*/ PIN_WIRE_SDA, /* reset=*/ U8X8_PIN_NONE);
// OLEDs without Reset of the Display
//const int buttonPin = 1; // the number of the pushbutton pin
int buttonState = 0; // variable for reading the pushbutton status
int BuzzerPin = A3;
int buzzer = BuzzerPin;
uint8_t interruptCount = 0; // Amount of received interrupts
uint8_t prevInterruptCount = 0; // Interrupt Counter from last loop
void setup() {
Serial.begin(9600);
delay(1000); //relax...
Serial.println("Processor came out of reset.\n");
u8x8.begin();
u8x8.setFlipMode(1); // set number from 1 to 3, the screen word will rotary 180
pinMode(LED_BUILTIN, OUTPUT);// initialize the LED pin as an output:
//pinMode(buttonPin, INPUT_PULLUP);// initialize the pushbutton pin as an input:
pinMode(BuzzerPin, OUTPUT);
pinMode(LED_RED, OUTPUT); //1.1.1
pinMode(LED_GREEN, OUTPUT);
pinMode(LED_BLUE, OUTPUT);
// pinMode(LEDR, OUTPUT); //2.9.2
// pinMode(LEDG, OUTPUT);
// pinMode(LEDB, OUTPUT);
setLedRGB(false, false, true); // set blue led
delay (2000);
startsound(); //Beep Buzzer speaker on A3
//initLeds(); // set pins
setupblink(); //Test RGB LED
myIMU.settings.gyroEnabled = 0; // Gyro currently not used, disabled to save power
if (myIMU.begin() != 0) {
Serial.println("IMU error");
} else {
Serial.println("IMU OK!");
}
Serial.println("\nLSM6D3 'High Level Example' compiled on "__DATE__ " at " __TIME__);
setupDoubleTapInterrupt();
pinMode(int1Pin, INPUT);
attachInterrupt(digitalPinToInterrupt(int1Pin), int1ISR, RISING);
u8x8.setFont(u8x8_font_8x13B_1x2_r);
u8x8.clearDisplay();
u8x8.setCursor(0, 0);
u8x8.print("Tap Demo");
}
void loop() {
setLedRGB(false, false, true); // reset led to blue only
u8x8.setCursor(0, 3);
u8x8.print(interruptCount);
//Serial.print("\Iterrupt Counter: ");
//Serial.println(interruptCount);
// if interrupt was received in this cycle
if (interruptCount > prevInterruptCount) {
Serial.println("\Interrupt received!");
setLedRGB(false, true, false); // set green only
}
prevInterruptCount = interruptCount;
if (interruptCount >= 3) {
// Trigger System OFF after 3 interrupts
goToPowerOff();
}
delay(500);
}
// -------------------- System ------------------------- //
void goToPowerOff() {
setLedRGB(false, false, false);
Serial.println("Going to System OFF");
u8x8.clearDisplay();
u8x8.setCursor(0, 3);
u8x8.print("SLEEP");
setupDoubleTapInterrupt(); // not needed here, if already applied..
delay(1000); // delay seems important to apply settings, before going to System OFF
//Ensure interrupt pin from IMU is set to wake up device
nrf_gpio_cfg_sense_input(digitalPinToInterrupt(int1Pin), NRF_GPIO_PIN_PULLDOWN, NRF_GPIO_PIN_SENSE_HIGH);
delay(2000); // Required delay
// Trigger System OFF
NRF_POWER->SYSTEMOFF = 1;
}
// -------------------- Interrupts ------------------------- //
void setupDoubleTapInterrupt() {
uint8_t error = 0;
uint8_t dataToWrite = 0;
// Double Tap Config
myIMU.writeRegister(LSM6DS3_ACC_GYRO_CTRL1_XL, 0x60); //* Acc = 416Hz (High-Performance mode)// Turn on the accelerometer
// ODR_XL = 416 Hz, FS_XL = 2g
myIMU.writeRegister(LSM6DS3_ACC_GYRO_TAP_CFG1, 0x8E);// INTERRUPTS_ENABLE, SLOPE_FDS// Enable interrupts and tap detection on X, Y, Z-axis
myIMU.writeRegister(LSM6DS3_ACC_GYRO_TAP_THS_6D, 0x85);// Set tap threshold 8C
myIMU.writeRegister(LSM6DS3_ACC_GYRO_INT_DUR2, 0x7F);// Set Duration, Quiet and Shock time windows 7F
myIMU.writeRegister(LSM6DS3_ACC_GYRO_WAKE_UP_THS, 0x80);// Single & double-tap enabled (SINGLE_DOUBLE_TAP = 1)
myIMU.writeRegister(LSM6DS3_ACC_GYRO_MD1_CFG, 0x08);// Double-tap interrupt driven to INT1 pin
}
void int1ISR()
{
interruptCount++;
;
}
// -------------------- Utilities ------------------------- //
void initLeds() {
pinMode(LED_RED, OUTPUT); // initialize the LED pin as an output:
pinMode(LED_GREEN, OUTPUT); // initialize the LED pin as an output:
pinMode(LED_BLUE, OUTPUT); // initialize the LED pin as an output:
pinMode(LED_BUILTIN, OUTPUT); // initialize the LED pin as an output:
}
void setupblink() {
setLedRGB(false, true, false); // Red
delay(1000);
setLedRGB(true, false, false); // Green
delay(1000);
setLedRGB(false, false, true); // Blue
delay(1000);
setLedRGB(false, false, false); // OFF
}
void startsound() {
tone(buzzer, 890);
delay(220);
noTone(buzzer);
delay(20);
tone(buzzer, 800);
delay(220);
noTone(buzzer);
delay(20);
tone(buzzer, 990);
delay(420);
noTone(buzzer);
}
void setLedRGB(bool red, bool green, bool blue) {
if (!blue) { digitalWrite(LED_BLUE, HIGH); } else { digitalWrite(LED_BLUE, LOW); }
if (!green) { digitalWrite(LED_GREEN, HIGH); } else { digitalWrite(LED_GREEN, LOW); }
if (!red) { digitalWrite(LED_RED, HIGH); } else { digitalWrite(LED_RED, LOW); }
}
Add the UNDERSCORE between the LED and Color. Works AOK.
Using library Seeed Arduino LSM6DS3 at version 2.0.3 in folder: C:\Users\Value Pawn\Documents\Arduino\libraries\Seeed_Arduino_LSM6DS3
Using library Wire at version 1.0 in folder: C:\Users\Value Pawn\AppData\Local\Arduino15\packages\Seeeduino\hardware\nrf52\1.1.1\libraries\Wire
Using library U8g2 at version 2.34.22 in folder: C:\Users\Value Pawn\Documents\Arduino\libraries\U8g2
Using library SPI at version 1.0 in folder: C:\Users\Value Pawn\AppData\Local\Arduino15\packages\Seeeduino\hardware\nrf52\1.1.1\libraries\SPI
Using library Adafruit TinyUSB Library at version 1.7.0 in folder: C:\Users\Value Pawn\AppData\Local\Arduino15\packages\Seeeduino\hardware\nrf52\1.1.1\libraries\Adafruit_TinyUSB_Arduino
"C:\\Users\\Value Pawn\\AppData\\Local\\Arduino15\\packages\\Seeeduino\\tools\\arm-none-eabi-gcc\\9-2019q4/bin/arm-none-eabi-size" -A "C:\\Users\\Value Pawn\\AppData\\Local\\Temp\\arduino\\sketches\\2DE1FA2DE1DD6F8494C9A4EA6C38C633/tap_demo_w_blink.ino.elf"
Sketch uses 53796 bytes (6%) of program storage space. Maximum is 811008 bytes.
Global variables use 7968 bytes (3%) of dynamic memory, leaving 229600 bytes for local variables. Maximum is 237568 bytes.
Performing 1200-bps touch reset on serial port COM21
Waiting for upload port...
Upload port found on COM22
"C:\Users\Value Pawn\AppData\Local\Arduino15\packages\Seeeduino\hardware\nrf52\1.1.1/tools/adafruit-nrfutil/win32/adafruit-nrfutil.exe" --verbose dfu serial -pkg "C:\Users\Value Pawn\AppData\Local\Temp\arduino\sketches\2DE1FA2DE1DD6F8494C9A4EA6C38C633/tap_demo_w_blink.ino.zip" -p COM22 -b 115200 --singlebank
Upgrading target on COM22 with DFU package C:\Users\Value Pawn\AppData\Local\Temp\arduino\sketches\2DE1FA2DE1DD6F8494C9A4EA6C38C633\tap_demo_w_blink.ino.zip. Flow control is disabled, Single bank, Touch disabled
Opened serial port COM22
Starting DFU upgrade of type 4, SoftDevice size: 0, bootloader size: 0, application size: 53804
Sending DFU start packet
Sending DFU init packet
Sending firmware file
########################################
########################################
##########################
Activating new firmware
DFU upgrade took 4.045702219009399s
Device programmed.
HTH
GL PJ