-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1136776
commit 065095f
Showing
3 changed files
with
65 additions
and
0 deletions.
There are no files selected for viewing
5 changes: 5 additions & 0 deletions
5
exampleCode/platform.io-example/MyFancyATmegaProject/.gitignore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
16 changes: 16 additions & 0 deletions
16
exampleCode/platform.io-example/MyFancyATmegaProject/platformio.ini
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
44
exampleCode/platform.io-example/MyFancyATmegaProject/src/main.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |