Skip to content

picowbell tripler demos #2815

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// SPDX-FileCopyrightText: 2024 Liz Clark for Adafruit Industries
//
// SPDX-License-Identifier: MIT

#include <Adafruit_NeoPixel.h>
#include <Adafruit_GFX.h> // Core graphics library
#include <Adafruit_ST7789.h> // Hardware-specific library for ST7789
#include <SPI.h>
#include <Fonts/FreeSansBold24pt7b.h>

#define LED LED_BUILTIN
#define TFT_CS 21
#define TFT_RST -1
#define TFT_DC 20
#define NEO_PIN A2

uint32_t Wheel(byte WheelPos);

Adafruit_ST7789 tft = Adafruit_ST7789(TFT_CS, TFT_DC, TFT_RST);

Adafruit_NeoPixel pixel = Adafruit_NeoPixel(1, NEO_PIN, NEO_GRB + NEO_KHZ800);

unsigned long lastMillis = 0;
uint8_t j = 0;

void setup() {
Serial.begin(115200);
//while (!Serial) delay(1); // wait for serial port
tft.init(240, 240);
pinMode(LED, OUTPUT);
delay (100);
Serial.println("PiCowbell Tripler Demo");
tft.setFont(&FreeSansBold24pt7b);
pixel.begin();
pixel.setBrightness(50);
pixel.show(); // Initialize all pixels to 'off'
lastMillis = millis();

}

void loop() {
if (millis() > (lastMillis + 5000)) {
digitalWrite(LED, HIGH);
// get the on-board voltage
float vsys = analogRead(A3) * 3 * 3.3 / 1023.0;
Serial.printf("Vsys: %0.1f V", vsys);
Serial.println();
digitalWrite(LED, LOW);
tft.fillScreen(ST77XX_BLACK);
tft.setCursor(240 / 4, 240 / 2);
tft.setTextColor(ST77XX_WHITE);
tft.printf("%0.1f V", vsys);
lastMillis = millis();
}
pixel.setPixelColor(0, Wheel(j++));
pixel.show();
delay(20);
}

uint32_t Wheel(byte WheelPos) {
WheelPos = 255 - WheelPos;
if(WheelPos < 85) {
return pixel.Color(255 - WheelPos * 3, 0, WheelPos * 3);
}
if(WheelPos < 170) {
WheelPos -= 85;
return pixel.Color(0, WheelPos * 3, 255 - WheelPos * 3);
}
WheelPos -= 170;
return pixel.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
}
54 changes: 54 additions & 0 deletions Tripler_PiCowbell_Demos/CircuitPython/code.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# SPDX-FileCopyrightText: Copyright (c) 2024 Liz Clark for Adafruit Industries
#
# SPDX-License-Identifier: MIT

import busio
import board
from analogio import AnalogIn
import adafruit_st7789
import displayio
import neopixel
from rainbowio import colorwheel
from adafruit_display_text import label
from adafruit_ticks import ticks_ms, ticks_add, ticks_diff
from font_orbitron_bold_webfont_36 import FONT as orbitron_font

displayio.release_displays()
spi = busio.SPI(clock=board.GP18, MOSI=board.GP19)
display_bus = displayio.FourWire(spi, command=board.GP20, chip_select=board.GP21, reset=None)
display = adafruit_st7789.ST7789(display_bus, width=240, height=240, rowstart=80, rotation=0)

group = displayio.Group()
text = label.Label(orbitron_font, text="0V", color=0xFF0000)
text.anchor_point = (0.5, 0.5)
text.anchored_position = (display.width / 2, display.height / 2)
group.append(text)
display.root_group = group

analog_in = AnalogIn(board.A3)

def get_vsys(pin):
return ((pin.value * 3) * 3.3) / 65535

pixel_pin = board.A2
num_pixels = 1
pixel = neopixel.NeoPixel(pixel_pin, num_pixels,
brightness=0.1, auto_write=True)
hue = 0
pixel.fill(colorwheel(hue))

bat_clock = ticks_ms()
bat_timer = 5000
neo_clock = ticks_ms()
neo_timer = 100

while True:
if ticks_diff(ticks_ms(), bat_clock) >= bat_timer:
print(f"The battery level is: {get_vsys(analog_in):.1f}V")
text.text = f"{get_vsys(analog_in):.1f}V"
text.color = colorwheel(hue)
bat_clock = ticks_add(bat_clock, bat_timer)
if ticks_diff(ticks_ms(), neo_clock) >= neo_timer:
hue = (hue + 7) % 256
pixel.fill(colorwheel(hue))
neo_clock = ticks_add(neo_clock, neo_timer)
Loading