Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * adc_driver.c
- *
- * Created: 09.09.2019 15:38:28
- * Author: chris
- */
- #include "header/initialize.h"
- #include "header/adc_driver.h"
- #include <stdint.h>
- #include <avr/interrupt.h>
- uint8_t percentage_from_8bit(uint8_t input_value) //Used if a percentage is more intuitive than 0-255. Delete if not needed.
- {
- uint8_t percentage = 100*(input_value)/255;
- return percentage;
- }
- char joystick_direction(uint8_t input_value,char axis)
- {
- if ((input_value < 124) & (axis == 'x')) {
- return 'L';
- }
- else if((input_value > 130) & (axis == 'x')) {
- return 'R';
- }
- else if((input_value < 124) & (axis == 'y')) {
- return 'D';
- }
- else if((input_value > 130) & (axis == 'y')) {
- return 'U';
- }
- else if((input_value <= 130) & (input_value >= 124)) {
- return 'N';
- }
- else {
- return 'E';
- }
- }
- uint8_t adc_read(uint8_t channel) //Value is returned through an ISR
- {
- volatile char *adc_address = 0x1400;
- switch (channel)
- {
- case 1 :
- adc_address[0] = 0b00000100; //Select channel 1
- break;
- case 2:
- adc_address[0] = 0b00000101; //Select channel 2
- break;
- case 3:
- adc_address[0] = 0b00000110; //Select channel 3
- break;
- case 4:
- adc_address[0] = 0b00000111; //Select channel 4
- break;
- default:
- printf("Invalid channel\r\n");
- }
- while(PIND &= (1 << PD3));
- return adc_address[0];
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement