-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into collision-avoidance
- Loading branch information
Showing
1 changed file
with
23 additions
and
0 deletions.
There are no files selected for viewing
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,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 |