Skip to content

Commit

Permalink
Add simavr example
Browse files Browse the repository at this point in the history
  • Loading branch information
SebastianZug committed Jan 24, 2024
1 parent 1136776 commit 065095f
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.pio
.vscode/.browse.c_cpp.db*
.vscode/c_cpp_properties.json
.vscode/launch.json
.vscode/ipch
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
; PlatformIO Project Configuration File
;
; Build options: build flags, source filter
; Upload options: custom upload port, speed and extra flags
; Library options: dependencies, extra library storages
; Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html

[env:uno]
platform = atmelavr
board = uno
framework = arduino

debug_tool = simavr
44 changes: 44 additions & 0 deletions exampleCode/platform.io-example/MyFancyATmegaProject/src/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#include <Arduino.h>
#include <stdint.h> // intxx_t und uintxx_t als Datentypen

int main(void)
{
uint16_t result = 0;

// enable ADC
ADCSRA |= (1 << ADEN);
// Setting the voltage reference to Arduino Input Power
ADMUX |= (1<<REFS0);
ADMUX &= ~(1<<REFS1);
// ADC Frequency should be between 50kHz and 200kHz, Arduiono clock is 16MHz
// setup the prescaler to 128 to get ADC Frequency of 16MHz/128 = 125kHz
ADCSRA |= (1 << ADPS2) | (1 << ADPS1) | (1<<ADPS0);
// set the ADC channel to ADC0
ADMUX &= ~((1<<MUX3)|(1<<MUX2)|(1<<MUX1)|(1<<MUX0));
// warmlaufen des ADC mittels "Dummy-Readout"
// ADC starten
ADCSRA |= (1<<ADSC);
// wait till conversion finished
while (ADCSRA & (1<<ADSC)) {}
// Preparation finished

Serial.begin(9600);

// Start continuous conversion
while (1)
{
result = 0;
// start the conversion
ADCSRA |= (1 << ADSC);
// wait until it's finished
while (ADCSRA & (1<<ADSC)) {}
// get the result
result = ADCW;

Serial.print(result);
Serial.print("\n");
Serial.flush();
}

return 0;
}

0 comments on commit 065095f

Please sign in to comment.