Skip to content

Commit 000ebe9

Browse files
sandeepmistrycmaglie
authored andcommitted
Initial import
0 parents  commit 000ebe9

40 files changed

+1724
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
/*
2+
Emoji Button
3+
4+
This example sends an emoji character over USB HID when the button is pressed.
5+
6+
Note: Only macOS and Linux as supported at this time, and the use of
7+
#define is generally discouraged in Arduino examples
8+
9+
The circuit:
10+
- Arduino Nano 33 BLE or Arduino Nano 33 BLE Sense board.
11+
- Button connected to pin 3 and GND.
12+
13+
Created by Don Coleman, Sandeep Mistry
14+
15+
This example code is in the public domain.
16+
*/
17+
18+
#include <PluggableUSBHID.h>
19+
#include <USBKeyboard.h>
20+
21+
// Select an OS:
22+
//#define MACOS // You'll need to enable and select the unicode keyboard: System Preferences -> Input Sources -> + -> Others -> Unicode Hex Input
23+
//#define LINUX
24+
25+
#if !defined(MACOS) && !defined(LINUX)
26+
#error "Please select an OS!"
27+
#endif
28+
29+
// use table: https://apps.timwhitlock.info/emoji/tables/unicode
30+
const int bicep = 0x1f4aa;
31+
const int punch = 0x1f44a;
32+
33+
const int buttonPin = 3;
34+
35+
USBKeyboard keyboard;
36+
37+
int previousButtonState = HIGH;
38+
39+
void setup() {
40+
pinMode(buttonPin, INPUT_PULLUP);
41+
}
42+
43+
void loop() {
44+
int buttonState = digitalRead(buttonPin);
45+
46+
if (buttonState != previousButtonState) {
47+
if (buttonState == LOW) {
48+
// pressed
49+
sentUtf8(bicep);
50+
} else {
51+
// released
52+
}
53+
54+
previousButtonState = buttonState;
55+
}
56+
}
57+
58+
void sentUtf8(unsigned long c) {
59+
String s;
60+
61+
#if defined(MACOS)
62+
// https://apple.stackexchange.com/questions/183045/how-can-i-type-unicode-characters-without-using-the-mouse
63+
64+
s = String(utf8ToUtf16(c), HEX);
65+
66+
for (int i = 0; i < s.length(); i++) {
67+
keyboard.key_code(s[i], KEY_ALT);
68+
}
69+
#elif defined(LINUX)
70+
s = String(c, HEX);
71+
72+
keyboard.key_code('u', KEY_CTRL | KEY_SHIFT);
73+
74+
for (int i = 0; i < s.length(); i++) {
75+
keyboard.key_code(s[i]);
76+
}
77+
#endif
78+
keyboard.key_code(' ');
79+
}
80+
81+
// based on https://stackoverflow.com/a/6240819/2020087
82+
unsigned long utf8ToUtf16(unsigned long in) {
83+
unsigned long result;
84+
85+
in -= 0x10000;
86+
87+
result |= (in & 0x3ff);
88+
result |= (in << 6) & 0x03ff0000;
89+
result |= 0xd800dc00;
90+
91+
return result;
92+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
Hardware Test
3+
4+
This example performs a basic hardware test of the board which includes
5+
testing the on-board IMU, LED and external button.
6+
7+
When the button is pressed the on-board LED will turn on.
8+
9+
The circuit:
10+
- Arduino Nano 33 BLE or Arduino Nano 33 BLE Sense board.
11+
- Button connected to pin 3 and GND.
12+
13+
Created by Don Coleman, Sandeep Mistry
14+
15+
This example code is in the public domain.
16+
*/
17+
18+
#include <Arduino_LSM9DS1.h>
19+
20+
const int buttonPin = 3;
21+
const int ledPin = LED_BUILTIN;
22+
23+
int buttonState = LOW;
24+
int previousButtonState = HIGH;
25+
26+
void setup() {
27+
Serial.begin(9600);
28+
//while (!Serial);
29+
Serial.println("Arduino ML Workshop Hardware Test");
30+
31+
if (!IMU.begin()) {
32+
Serial.println("Failed to initialize IMU!");
33+
while (1);
34+
}
35+
36+
// initialize the LED pin as an output:
37+
pinMode(ledPin, OUTPUT);
38+
// initialize the push button pin as an input with (internal) pullup:
39+
pinMode(buttonPin, INPUT_PULLUP);
40+
}
41+
42+
void loop() {
43+
// read the state of the push button pin:
44+
buttonState = digitalRead(buttonPin);
45+
46+
// HIGH and LOW are opposite because of we are using an internal pullup resistor.
47+
// LOW is pressed. HIGH is released.
48+
49+
if (buttonState == LOW) {
50+
// Button is pressed, turn the LED on
51+
digitalWrite(ledPin, HIGH);
52+
if (buttonState != previousButtonState) {
53+
Serial.println("LED is ON");
54+
}
55+
} else {
56+
// Button is released, turn the LED off
57+
digitalWrite(ledPin, LOW);
58+
if (buttonState != previousButtonState) {
59+
Serial.println("LED is OFF");
60+
}
61+
}
62+
63+
// save the previous state of the button since we only print
64+
// the LED status when the state changes
65+
previousButtonState = buttonState;
66+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
/*
2+
IMU Capture
3+
4+
This example uses the on-board IMU to start reading acceleration and gyroscope
5+
data from on-board IMU and prints it to the Serial Monitor for one second
6+
when the significant motion is detected.
7+
8+
You can also use the Serial Plotter to graph the data.
9+
10+
The circuit:
11+
- Arduino Nano 33 BLE or Arduino Nano 33 BLE Sense board.
12+
13+
Created by Don Coleman, Sandeep Mistry
14+
Modified by Dominic Pajak, Sandeep Mistry
15+
16+
This example code is in the public domain.
17+
*/
18+
19+
#include <Arduino_LSM9DS1.h>
20+
21+
const float accelerationThreshold = 2.5; // threshold of significant in G's
22+
const int numSamples = 119;
23+
24+
int samplesRead = numSamples;
25+
26+
void setup() {
27+
Serial.begin(9600);
28+
while (!Serial);
29+
30+
if (!IMU.begin()) {
31+
Serial.println("Failed to initialize IMU!");
32+
while (1);
33+
}
34+
35+
// print the header
36+
Serial.println("aX,aY,aZ,gX,gY,gZ");
37+
}
38+
39+
void loop() {
40+
float aX, aY, aZ, gX, gY, gZ;
41+
42+
// wait for significant motion
43+
while (samplesRead == numSamples) {
44+
if (IMU.accelerationAvailable()) {
45+
// read the acceleration data
46+
IMU.readAcceleration(aX, aY, aZ);
47+
48+
// sum up the absolutes
49+
float aSum = fabs(aX) + fabs(aY) + fabs(aZ);
50+
51+
// check if it's above the threshold
52+
if (aSum >= accelerationThreshold) {
53+
// reset the sample read count
54+
samplesRead = 0;
55+
break;
56+
}
57+
}
58+
}
59+
60+
// check if the all the required samples have been read since
61+
// the last time the significant motion was detected
62+
while (samplesRead < numSamples) {
63+
// check if both new acceleration and gyroscope data is
64+
// available
65+
if (IMU.accelerationAvailable() && IMU.gyroscopeAvailable()) {
66+
// read the acceleration and gyroscope data
67+
IMU.readAcceleration(aX, aY, aZ);
68+
IMU.readGyroscope(gX, gY, gZ);
69+
70+
samplesRead++;
71+
72+
// print the data in CSV format
73+
Serial.print(aX, 3);
74+
Serial.print(',');
75+
Serial.print(aY, 3);
76+
Serial.print(',');
77+
Serial.print(aZ, 3);
78+
Serial.print(',');
79+
Serial.print(gX, 3);
80+
Serial.print(',');
81+
Serial.print(gY, 3);
82+
Serial.print(',');
83+
Serial.print(gZ, 3);
84+
Serial.println();
85+
86+
if (samplesRead == numSamples) {
87+
// add an empty line if it's the last sample
88+
Serial.println();
89+
}
90+
}
91+
}
92+
}

0 commit comments

Comments
 (0)