mirror of
https://codeberg.org/scip/attinycore-makefile-tests.git
synced 2025-12-16 19:00:57 +01:00
105 lines
2.0 KiB
C++
105 lines
2.0 KiB
C++
/* -*-c++-*-
|
|
Blink
|
|
Turns on an LED on for one second, then off for one second, repeatedly.
|
|
This example code is in the public domain.
|
|
*/
|
|
|
|
/*
|
|
./hardware/ATTinyCore/avr/cores/tinymodern/core_pins.h
|
|
Caution: reverse Pinout: PA3 => Pin 3
|
|
|
|
Nanite841 Pinout from above:
|
|
|
|
button
|
|
SDO/MISO PA5 PA6 SDI/MOSI
|
|
SCK PA4 PA7
|
|
CS PA3 PB2
|
|
RX0 PA2 PB2
|
|
TX0 PA1 PB1
|
|
PA0 PB0
|
|
GND VCC
|
|
usb
|
|
|
|
Bosch BME280 Breakout from above pin header left:
|
|
|
|
VCC
|
|
GND
|
|
SCL => SCK
|
|
SDI => MOSI
|
|
CSB => PA3/3
|
|
SDO => MISO
|
|
|
|
*/
|
|
|
|
#define TINY_BME280_SPI
|
|
#include <TinyBME280.h>
|
|
|
|
#define LED 2 //LED_BUILTIN // PORTB2
|
|
#define CS 3
|
|
|
|
static tiny::BME280 sensor;
|
|
|
|
#define SET_OUTPUT(pin) DDRB |= (1 << pin)
|
|
#define SET_HIGH(pin) PORTB |= (1 << pin)
|
|
#define SET_LOW(pin) PORTB &= ~(1 << pin)
|
|
|
|
void print_asufloat(uint32_t val, uint16_t factor) {
|
|
Serial.print(val / factor);
|
|
Serial.print(".");
|
|
Serial.print(val % factor);
|
|
}
|
|
|
|
void print_asifloat(int32_t val, uint16_t factor) {
|
|
Serial.print(val / factor);
|
|
Serial.print(".");
|
|
Serial.print(val % factor);
|
|
}
|
|
|
|
void print_measurements() {
|
|
uint32_t pres, humidity;
|
|
int32_t temp;
|
|
|
|
temp = sensor.readFixedTempC();
|
|
humidity = sensor.readFixedHumidity();
|
|
pres = sensor.readFixedPressure();
|
|
|
|
SET_LOW(LED);
|
|
|
|
Serial.print(" Temperature: ");
|
|
print_asifloat(temp, 100);
|
|
Serial.println(" Grad C");
|
|
|
|
Serial.print(" Pressure: ");
|
|
print_asufloat(pres, 100);
|
|
Serial.println(" hPa");
|
|
|
|
Serial.print(" Humidity: ");
|
|
print_asufloat(humidity, 1000);
|
|
Serial.println(" %");
|
|
|
|
Serial.println();
|
|
|
|
SET_HIGH(LED);
|
|
}
|
|
|
|
void halt() {
|
|
while(1);
|
|
}
|
|
|
|
void setup() {
|
|
SET_OUTPUT(LED);
|
|
Serial.begin(115200);
|
|
Serial.println("init");
|
|
if(sensor.beginSPI(CS) == false) {
|
|
Serial.println("Sensor BME280 connect failed, check wiring!");
|
|
halt();
|
|
}
|
|
|
|
}
|
|
|
|
void loop() {
|
|
print_measurements();
|
|
delay(2000);
|
|
}
|
|
|