Skip to content

Commit

Permalink
Merge branch 'main' into collision-avoidance
Browse files Browse the repository at this point in the history
  • Loading branch information
PacoRmzA committed May 20, 2022
2 parents e36b6d2 + 62a68bd commit 6bb71b4
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions CleanIt-SC/Headers/limit_switch.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#ifndef LIMIT_SWITCH_H
#define LIMIT_SWITCH_H
#include "MKL25Z4.h"
#define SWITCH_FRONT 0
#define SWITCH_LEFT 1
#define SWITCH_RIGHT 2

void limit_switch_init(void);
bool hasNOT_collided(int pinNumber);

void limit_switch_init(void){
SIM->SCGC5 |= 0x0800; /* enable clock to Port C */
PORTC->PCR[0] = 0x103; /* PTC0, GPIO, enable pullup*/
PORTC->PCR[1] = 0x103; /* PTC1, GPIO, enable pullup*/
PORTC->PCR[2] = 0x103; /* PTC2, GPIO, enable pullup*/
PTC->PDDR = 0x07; /* make PTC2-0 as input pins */
}

bool hasNOT_collided(int pinNumber) {
return PTC->PDIR & (0x01 << pinNumber);
}

#endif

0 comments on commit 6bb71b4

Please sign in to comment.