update ball_read to use registers instead of pinMode and digitalWrite
also move all the files relative to 32u4 uC inside a dedicated folder add the Blink script i made to test if everything was working and to test registers for LEDspull/1/head
parent
b17e54ae27
commit
978be20b03
|
@ -0,0 +1,36 @@
|
||||||
|
/*For some reason in our board, which I've been explained but I'm not capable of explaining it again, including LED1 and LED4 being part of usb serial,
|
||||||
|
we can't use plain pinMode and digitalWrite on those pins (at least the output ones, for what I've tried so far), so we gotta use registers and modify them manually
|
||||||
|
While this is a bit of a PITA, runs faster on the the uC
|
||||||
|
Also using Arduino Micro bootloader, seems to work fine
|
||||||
|
If Arduino Micro bl doesn't appear to work right, try the Sparkfun ProMicro ones
|
||||||
|
|
||||||
|
-EmaMaker 29/11/2020 22:47 CET
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
// the setup function runs once when you press reset or power the board
|
||||||
|
void setup() {
|
||||||
|
//LED3(PB7) and LED4 (PB0)
|
||||||
|
DDRB=0b10000001;
|
||||||
|
//LED2 (PF0)
|
||||||
|
DDRF=0b00000001;
|
||||||
|
//LED1 (PD5)
|
||||||
|
DDRD=0b00100000;
|
||||||
|
}
|
||||||
|
|
||||||
|
// the loop function runs over and over again forever
|
||||||
|
void loop() {
|
||||||
|
//Set the pins HIGH, using OR the pins we don't care about are not touched
|
||||||
|
PORTB = PORTB | 0b10000001;
|
||||||
|
PORTF = PORTF | 0b00000001;
|
||||||
|
PORTD = PORTD | 0b00100000;
|
||||||
|
|
||||||
|
delay(1000);
|
||||||
|
|
||||||
|
//Set the pins LOW, using AND the pins we don't care about are not touched
|
||||||
|
PORTB = PORTB & 0b01111110;
|
||||||
|
PORTF = PORTF & 0b01111110;
|
||||||
|
PORTD = PORTD & 0b11011111;
|
||||||
|
|
||||||
|
delay(1000);
|
||||||
|
}
|
|
@ -1,8 +1,8 @@
|
||||||
#define BTN0 A3
|
#define BTN0 A3
|
||||||
#define BTN1 A4
|
#define BTN1 A4
|
||||||
#define BTN2 A5
|
#define BTN2 A5
|
||||||
#define LED_Y 11
|
#define LED_Y 41
|
||||||
#define LED_R 17
|
#define LED_R 22
|
||||||
|
|
||||||
void setup (){
|
void setup (){
|
||||||
Serial1.begin(19200);
|
Serial1.begin(19200);
|
||||||
|
@ -20,10 +20,10 @@ void loop () {
|
||||||
//We have three config. buttons, making a packet out of a single byte with a start header, so teensy can use it as it wants
|
//We have three config. buttons, making a packet out of a single byte with a start header, so teensy can use it as it wants
|
||||||
//The header is signed by the two most important bits put high, so 128+64 in OR with other bits shifted by the needed ammount
|
//The header is signed by the two most important bits put high, so 128+64 in OR with other bits shifted by the needed ammount
|
||||||
//This approach only admits 5 configuration buttons, it should be enough
|
//This approach only admits 5 configuration buttons, it should be enough
|
||||||
b = 0b11000000;
|
b = 0b11000111;
|
||||||
b |= digitalRead(BTN0);
|
//b |= digitalRead(BTN0);
|
||||||
b |= digitalRead(BTN1) << 1;
|
//b |= digitalRead(BTN1) << 1;
|
||||||
b |= digitalRead(BTN2) << 2;
|
//b |= digitalRead(BTN2) << 2;
|
||||||
if(oldB != b) Serial1.write(b);
|
if(oldB != b) Serial1.write(b);
|
||||||
oldB = b;
|
oldB = b;
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
{
|
||||||
|
// See http://go.microsoft.com/fwlink/?LinkId=827846
|
||||||
|
// for the documentation about the extensions.json format
|
||||||
|
"recommendations": [
|
||||||
|
"platformio.platformio-ide"
|
||||||
|
]
|
||||||
|
}
|
|
@ -45,6 +45,16 @@
|
||||||
#define BROKEN 300
|
#define BROKEN 300
|
||||||
#define TOO_LOW 60
|
#define TOO_LOW 60
|
||||||
|
|
||||||
|
#define LED1ON (PORTD = PORTD | 0b00100000)
|
||||||
|
#define LED1OFF (PORTD & 0b11011111)
|
||||||
|
#define LED2ON (PORTD = PORTD | 0b00100000)
|
||||||
|
#define LED2OFF (PORTF & 0b01111110)
|
||||||
|
#define LED3ON (PORTB | 0b10000000)
|
||||||
|
#define LED3OFF (PORTB & 0b01111111)
|
||||||
|
#define LED4ON (PORTB | 0b00000001)
|
||||||
|
#define LED4OFF (PORTB & 0b11111110)
|
||||||
|
|
||||||
|
|
||||||
int counter[16];
|
int counter[16];
|
||||||
int distance;
|
int distance;
|
||||||
int nmax = 0;
|
int nmax = 0;
|
||||||
|
@ -64,13 +74,13 @@ byte sendAngle = 0, sendDistance = 0;
|
||||||
byte sendByte = 0;
|
byte sendByte = 0;
|
||||||
|
|
||||||
unsigned long t = 0;
|
unsigned long t = 0;
|
||||||
t
|
|
||||||
void setup() {
|
void setup() {
|
||||||
delay(1000);
|
delay(1000);
|
||||||
|
|
||||||
Serial.begin(57600);
|
Serial.begin(57600);
|
||||||
|
|
||||||
pinMode(26, INPUT); //S1
|
/*pinMode(26, INPUT); //S1
|
||||||
pinMode(25, INPUT); //S2
|
pinMode(25, INPUT); //S2
|
||||||
pinMode(19, INPUT); //S3
|
pinMode(19, INPUT); //S3
|
||||||
pinMode(18, INPUT); //S4
|
pinMode(18, INPUT); //S4
|
||||||
|
@ -85,9 +95,21 @@ void setup() {
|
||||||
pinMode(30, INPUT); //S13
|
pinMode(30, INPUT); //S13
|
||||||
pinMode(29, INPUT); //S14
|
pinMode(29, INPUT); //S14
|
||||||
pinMode(28, INPUT); //S15
|
pinMode(28, INPUT); //S15
|
||||||
pinMode(27, INPUT); //S16
|
pinMode(27, INPUT); //S16*/
|
||||||
|
|
||||||
pinMode(22, OUTPUT); //LED1
|
/*For now replace pinMode with writes to the direction register.
|
||||||
|
We don't know if pinMode will work on those sensors, and it has proven not be working on digitalWrite for reasons probably relative to compatibility between Arduino and our board,
|
||||||
|
but this needs further investigation*/
|
||||||
|
|
||||||
|
//Set the LEDs as outputs, keep the rest as input by default
|
||||||
|
|
||||||
|
//LED3(PB7) and LED4 (PB0)
|
||||||
|
DDRB=0b10000001;
|
||||||
|
//LED2 (PF0)
|
||||||
|
DDRF=0b00000001;
|
||||||
|
//LED1 (PD5)
|
||||||
|
DDRD=0b00100000;
|
||||||
|
DDRE = 0b00000000;
|
||||||
|
|
||||||
for (int i = 0; i < 16; i++) {
|
for (int i = 0; i < 16; i++) {
|
||||||
xs[i] = cos((22.5 * PI / 180) * i);
|
xs[i] = cos((22.5 * PI / 180) * i);
|
||||||
|
@ -153,9 +175,9 @@ void readBallInterpolation() {
|
||||||
|
|
||||||
//turn led on
|
//turn led on
|
||||||
if (dist == 0) {
|
if (dist == 0) {
|
||||||
digitalWrite(22, LOW);
|
LED1ON;
|
||||||
} else {
|
} else {
|
||||||
digitalWrite(22, HIGH);
|
LED1OFF;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +0,0 @@
|
||||||
{
|
|
||||||
// See http://go.microsoft.com/fwlink/?LinkId=827846
|
|
||||||
// for the documentation about the extensions.json format
|
|
||||||
"recommendations": [
|
|
||||||
"platformio.platformio-ide"
|
|
||||||
]
|
|
||||||
}
|
|
Loading…
Reference in New Issue