Skip to content

Commit

Permalink
Completed Proximity_read function, changed its return type to int
Browse files Browse the repository at this point in the history
  • Loading branch information
PAOK-2001 committed May 16, 2022
1 parent baf2711 commit 478056c
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions CleanIt-SC/Headers/proximity.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#ifndef PROXIMITY_H
#define PROXIMITY_H
#include <MKL25Z4.h>
#include "delays.h"

void adc_init(void);
void proximity_init(void);
uint16_t proximity_read(void);
int proximity_read(void);

//adc_init()
// Initialized clock for ADC0 and configures necessary register.
Expand All @@ -14,7 +15,7 @@ void adc_init(void){
/*CLKDIV/4, LS time, single ended 12 bit, bus clock */
ADC0->CFG1 = 0x40 | 0x10 | 0x04 | 0x00;
}
//Proximity_init
//proximity_init()
// Configure necessary ports as analogue
void proximity_init(void){
// Initialize clock to PORTB
Expand All @@ -25,9 +26,11 @@ void proximity_init(void){
adc_init();
}

uint16_t proximity_read(int sensorChannel){
uint16_t readValue;

int proximity_read(int sensorChannel){
int readValue;
ADC0->SC1[0] = sensorChannel;
while(!(ADC0->SC1[0] & 0x80)) { } /* wait for COCO */
readValue = ADC0->R[0];
return readValue;
}

Expand Down

0 comments on commit 478056c

Please sign in to comment.