#include "global.h"
#define LED_HEARTBEAT 13
#define LED_EXTERNAL 7
#define SENSOR_BUTTON 4
void setup() {
// put your setup code here, to run once:
////// EXAMPLE
/// ERROR SHOOTIGN RELATED TO PIN DECLARE ERROR
SYS_ERROR_CODE = GPIO_Mode(10, GPIO_OUTPUT);
//SYS_ERROR_CHECK(GPIO_Mode(10, GPIO_OUTPUT)); // LAGI SENANG NK BACA
SYS_ERROR_CODE = GPIO_Write(4, GPIO_HIGH);
GPIO_Mode(LED_HEARTBEAT, GPIO_OUTPUT);
// target for Arduino Uno only
//DDRD |= 0x80; // GPIO 7 as output for external LED
GPIO_Mode(LED_EXTERNAL, GPIO_OUTPUT);
//INPUT
//DDRD &= ~INIT_PD4; // PIN 4
GPIO_Mode(SENSOR_BUTTON, GPIO_INPUT);
// From schematic PD4 <-- PIN 4
GPIO_Mode(40, GPIO_INPUT); // x acceptable sbb Arduino x da pin 40
// So this should fail, so have to do more error handling
}
void loop() {
// put your main code here, to run repeatedly:
// put your main code here, to run repeatedly:
uint8_t i;
GPIO_Read(SENSOR_BUTTON, &i);
if ( PIND & 0x10 ) // XXX? XXXX
/* 7 6 5 4 3 2 1 0
PIND : X X X ? X X X X
& 0 0 0 1 0 0 0 0
----------------------
0 0 0 0 0 0 0 0
or 0 0 0 1 0 0 0 0
---> Depending on value of PIN4 input
*/
{
GPIO_Write(LED_EXTERNAL, GPIO_HIGH);
//PORTD |= 0x80;
}
else
{
GPIO_Write(LED_EXTERNAL, GPIO_LOW);
//PORTD &= ~0x80;
}
//digitalWrite(13, HIGH);
//PORTB = PORTB | 0x20; // ON
GPIO_Write(LED_HEARTBEAT, GPIO_HIGH);
// PORTB |= 0x20;
for (i = 0 ; i < 100000 ; i++);
//digitalWrite(13, LOW);
//PORTB = PORTB & ~0x20; // OFF
GPIO_Write(LED_HEARTBEAT, GPIO_LOW);
// PORTB &= ~0x20;
for (i = 0 ; i < 100000 ; i++); // delay
}