Skip to content

Commit 7715542

Browse files
Merge branch 'adafruit:main' into main
2 parents 2247388 + 6d19471 commit 7715542

4 files changed

Lines changed: 189 additions & 1 deletion

File tree

ANO_encoder_demo/.feather_m0_express.test.only

Whitespace-only changes.
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
#include <Adafruit_NeoPixel.h>
2+
#include <RotaryEncoder.h>
3+
4+
#define PIN_ENCODER_A 12
5+
#define PIN_ENCODER_B 13
6+
#define COM_A 11 // for wiring simplicity we set these output LOW
7+
#define COM_B SDA // ... but you can just wire these to GND instead!
8+
#define BUTTON_UP SCL
9+
#define BUTTON_LEFT 5
10+
#define BUTTON_DOWN 6
11+
#define BUTTON_RIGHT 9
12+
#define BUTTON_IN 10
13+
14+
RotaryEncoder encoder(PIN_ENCODER_A, PIN_ENCODER_B, RotaryEncoder::LatchMode::TWO03);
15+
// This interrupt will do our encoder reading/checking!
16+
void checkPosition() {
17+
encoder.tick(); // just call tick() to check the state.
18+
}
19+
int last_rotary = 0;
20+
21+
22+
#define NUMPIXELS 12
23+
Adafruit_NeoPixel pixels(NUMPIXELS, A0, NEO_GRB + NEO_KHZ800);
24+
25+
26+
void setup(void) {
27+
Serial.begin(115200);
28+
// while (!Serial);
29+
Serial.println("ANO encoder + NeoPixel test");
30+
31+
pinMode(COM_A, OUTPUT);
32+
digitalWrite(COM_A, LOW);
33+
pinMode(COM_B, OUTPUT);
34+
digitalWrite(COM_B, LOW);
35+
36+
attachInterrupt(PIN_ENCODER_A, checkPosition, CHANGE);
37+
attachInterrupt(PIN_ENCODER_B, checkPosition, CHANGE);
38+
39+
pinMode(BUTTON_UP, INPUT_PULLUP);
40+
pinMode(BUTTON_DOWN, INPUT_PULLUP);
41+
pinMode(BUTTON_LEFT, INPUT_PULLUP);
42+
pinMode(BUTTON_RIGHT, INPUT_PULLUP);
43+
pinMode(BUTTON_IN, INPUT_PULLUP);
44+
pixels.begin();
45+
pixels.setBrightness(30);
46+
pixels.show();
47+
}
48+
49+
50+
void loop(void) {
51+
// read encoder
52+
int curr_rotary = encoder.getPosition();
53+
RotaryEncoder::Direction direction = encoder.getDirection();
54+
55+
pixels.clear();
56+
if (curr_rotary != last_rotary) {
57+
Serial.print("Encoder value: ");
58+
Serial.print(curr_rotary);
59+
Serial.print(" direction: ");
60+
Serial.println((int)direction);
61+
}
62+
last_rotary = curr_rotary;
63+
64+
pixels.setPixelColor((curr_rotary + (1000*NUMPIXELS)) % NUMPIXELS, pixels.Color(0, 150, 0));
65+
66+
if (! digitalRead(BUTTON_UP)) {
67+
pixels.setPixelColor(0, pixels.Color(150, 0, 0));
68+
}
69+
if (! digitalRead(BUTTON_LEFT)) {
70+
pixels.setPixelColor(NUMPIXELS/4, pixels.Color(150, 0, 0));
71+
}
72+
if (! digitalRead(BUTTON_DOWN)) {
73+
pixels.setPixelColor(NUMPIXELS/2, pixels.Color(150, 0, 0));
74+
}
75+
if (! digitalRead(BUTTON_RIGHT)) {
76+
pixels.setPixelColor(NUMPIXELS*3/4, pixels.Color(150, 0, 0));
77+
}
78+
if (! digitalRead(BUTTON_IN)) {
79+
pixels.fill(pixels.Color(50, 50, 50));
80+
}
81+
pixels.show();
82+
83+
delay(20);
84+
}

BLE_Gesture_Mouse/code.py

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
import time
2+
import board
3+
import digitalio
4+
import simpleio
5+
import adafruit_lsm6ds.lsm6ds33
6+
import adafruit_apds9960.apds9960
7+
from adafruit_hid.mouse import Mouse
8+
9+
import adafruit_ble
10+
from adafruit_ble.advertising import Advertisement
11+
from adafruit_ble.advertising.standard import ProvideServicesAdvertisement
12+
from adafruit_ble.services.standard.hid import HIDService
13+
from adafruit_ble.services.standard.device_info import DeviceInfoService
14+
15+
# setup I2C
16+
i2c = board.I2C()
17+
18+
# setup accelerometer
19+
lsm6ds33 = adafruit_lsm6ds.lsm6ds33.LSM6DS33(i2c)
20+
# setup proximity sensor
21+
apds9960 = adafruit_apds9960.apds9960.APDS9960(i2c)
22+
23+
# enable proximity sensor
24+
apds9960.enable_proximity = True
25+
26+
# setup for onboard button
27+
click = digitalio.DigitalInOut(board.SWITCH)
28+
click.direction = digitalio.Direction.INPUT
29+
click.pull = digitalio.Pull.UP
30+
31+
# rounding algorhythm used for mouse movement
32+
# as used in the HID mouse CircuitPython example
33+
mouse_min = -9
34+
mouse_max = 9
35+
step = (mouse_max - mouse_min) / 20.0
36+
37+
def steps(axis):
38+
return round((axis - mouse_min) / step)
39+
40+
# time.monotonic() variable
41+
clock = 0
42+
43+
# variable for distance for proximity scrolling
44+
distance = 245
45+
46+
# setup for HID and BLE
47+
hid = HIDService()
48+
49+
device_info = DeviceInfoService(software_revision=adafruit_ble.__version__,
50+
manufacturer="Adafruit Industries")
51+
advertisement = ProvideServicesAdvertisement(hid)
52+
advertisement.appearance = 961
53+
scan_response = Advertisement()
54+
scan_response.complete_name = "CircuitPython HID"
55+
56+
ble = adafruit_ble.BLERadio()
57+
58+
if not ble.connected:
59+
print("advertising")
60+
ble.start_advertising(advertisement, scan_response)
61+
else:
62+
print("already connected")
63+
print(ble.connections)
64+
65+
# setup for mouse
66+
mouse = Mouse(hid.devices)
67+
68+
while True:
69+
while not ble.connected:
70+
pass
71+
while ble.connected:
72+
# sets x and y values for accelerometer x and y values
73+
# x and y are swapped for orientation of feather
74+
y, x, z = lsm6ds33.acceleration
75+
76+
# map range of horizontal movement to mouse x movement
77+
horizontal_mov = simpleio.map_range(steps(x), 1.0, 20.0, -15.0, 15.0)
78+
# map range of vertical movement to mouse y movement
79+
vertical_mov = simpleio.map_range(steps(y), 20.0, 1.0, -15.0, 15.0)
80+
# map range of mouse y movement to scrolling
81+
scroll_dir = simpleio.map_range(vertical_mov, -15.0, 15.0, 3.0, -3.0)
82+
83+
# if onboard button is pressed, sends left mouse click
84+
if not click.value:
85+
mouse.click(Mouse.LEFT_BUTTON)
86+
time.sleep(0.2)
87+
# if the proximity sensor is covered
88+
# scroll the mouse
89+
if apds9960.proximity > distance:
90+
mouse.move(wheel=int(scroll_dir))
91+
# otherwise move mouse cursor in x and y directions
92+
else:
93+
mouse.move(x=int(horizontal_mov))
94+
mouse.move(y=int(vertical_mov))
95+
96+
# debugging print for x and y values
97+
# time.monotonic() is used so that the
98+
# code is not delayed with time.sleep
99+
if (clock + 2) < time.monotonic():
100+
print("x", steps(x))
101+
print("y", steps(y))
102+
clock = time.monotonic()
103+
104+
ble.start_advertising(advertisement)

library.deps

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
depends=Adafruit ILI9341, Adafruit BusIO, SD, Adafruit NeoPixel, Adafruit VS1053 Library, Adafruit BluefruitLE nRF51, Adafruit seesaw Library, Ethernet, Adafruit IO Arduino, FastLED, Adafruit LiquidCrystal, Adafruit SoftServo, TinyWireM, Adafruit AM radio library, WaveHC, Adafruit LED Backpack Library, MAX31850 OneWire, Adafruit VC0706 Serial Camera Library, RTClib, Adafruit SleepyDog Library, Adafruit Thermal Printer Library, Adafruit Zero I2S Library, Adafruit EPD, Adafruit SSD1351 library, Adafruit FONA Library, Adafruit Motor Shield V2 Library, Adafruit NeoMatrix, Adafruit Soundboard library, Adafruit Circuit Playground, ArduinoJson, Adafruit TCS34725, Adafruit Pixie, Adafruit GPS Library, TinyGPS, WiFi101, Adafruit DotStar, Adafruit Si7021 Library, Adafruit WS2801 Library, Mouse, Keyboard, Time, IRremote, Adafruit LSM9DS0 Library, Adafruit Arcada Library, MIDIUSB, PubSubClient, Adafruit LIS2MDL, Adafruit NeoPXL8, Adafruit MCP23017 Arduino Library, Adafruit MLX90640, LiquidCrystal, Adafruit NeoTrellis M4 Library, RGB matrix Panel, Adafruit MLX90614 Library, Adafruit RGB LCD Shield Library, MAX6675 library, Adafruit MP3, Adafruit Keypad, Adafruit Arcada GifDecoder, Keypad, Neosegment, Encoder, Adafruit TiCoServo, Adafruit Trellis Library, FauxmoESP, Adafruit LSM303 Accel, Adafruit LSM303DLH Mag, CapacitiveSensor, Adafruit Zero PDM Library, Adafruit DMA neopixel library, elapsedMillis, DST RTC, Adafruit SHARP Memory Display, Adafruit SPIFlash, BSEC Software Library, WiiChuck, Adafruit DPS310, Adafruit AHTX0
1+
depends=Adafruit ILI9341, Adafruit BusIO, SD, Adafruit NeoPixel, Adafruit VS1053 Library, Adafruit BluefruitLE nRF51, Adafruit seesaw Library, Ethernet, Adafruit IO Arduino, FastLED, Adafruit LiquidCrystal, Adafruit SoftServo, TinyWireM, Adafruit AM radio library, WaveHC, Adafruit LED Backpack Library, MAX31850 OneWire, Adafruit VC0706 Serial Camera Library, RTClib, Adafruit SleepyDog Library, Adafruit Thermal Printer Library, Adafruit Zero I2S Library, Adafruit EPD, Adafruit SSD1351 library, Adafruit FONA Library, Adafruit Motor Shield V2 Library, Adafruit NeoMatrix, Adafruit Soundboard library, Adafruit Circuit Playground, ArduinoJson, Adafruit TCS34725, Adafruit Pixie, Adafruit GPS Library, TinyGPS, WiFi101, Adafruit DotStar, Adafruit Si7021 Library, Adafruit WS2801 Library, Mouse, Keyboard, Time, IRremote, Adafruit LSM9DS0 Library, Adafruit Arcada Library, MIDIUSB, PubSubClient, Adafruit LIS2MDL, Adafruit NeoPXL8, Adafruit MCP23017 Arduino Library, Adafruit MLX90640, LiquidCrystal, Adafruit NeoTrellis M4 Library, RGB matrix Panel, Adafruit MLX90614 Library, Adafruit RGB LCD Shield Library, MAX6675 library, Adafruit MP3, Adafruit Keypad, Adafruit Arcada GifDecoder, Keypad, Neosegment, Encoder, Adafruit TiCoServo, Adafruit Trellis Library, FauxmoESP, Adafruit LSM303 Accel, Adafruit LSM303DLH Mag, CapacitiveSensor, Adafruit Zero PDM Library, Adafruit DMA neopixel library, elapsedMillis, DST RTC, Adafruit SHARP Memory Display, Adafruit SPIFlash, BSEC Software Library, WiiChuck, Adafruit DPS310, Adafruit AHTX0, RotaryEncoder

0 commit comments

Comments
 (0)