Got analog input working.

This commit is contained in:
Marvin Blum
2017-03-21 22:50:17 +01:00
parent fbf8bd8a4f
commit 3c4451e1bb
3 changed files with 39 additions and 22 deletions

22
main.c
View File

@@ -1,5 +1,7 @@
#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>
#include <stdio.h>
#include "serial.h"
#include "pins.h"
@@ -15,14 +17,21 @@ int main(){
}
void prepare(){
// enable global interrupts and serial port
sei();
serial_init(9600);
// digital input/output example
/*pin_mode(11, OUTPUT);
pin_mode(10, INPUT);
pin_mode(8, INPUT);*/
// anlog input example
pin_mode(A4, INPUT);
}
void loop(){
// digital input/output example
/*if(digital_read(10) && digital_read(8)){
digital_write(11, HIGH);
}
@@ -30,12 +39,11 @@ void loop(){
digital_write(11, LOW);
}*/
if(analog_read(A4) > 0){
serial_write("ok", 3);
}
else{
serial_write("nope", 5);
}
// anlog input example
int analog = analog_read(A4);
char out[15];
sprintf(out, "%d", analog);
serial_write(out, 15);
_delay_ms(25);
}