Hello,
KurtEck thanks for the reply. I saw your code and there are functions you used that I have not thought they exist and can get my code even cleaner.
------Digital outputs--------
I found how to do it. And Is very simple:
appInitHardware:
pin_make_output(B6); // declare the B6 port as output
appControl
pin_high(B6);//on fan
delay_ms(5000);//Delay in ms ... 5000ms = 5seconds
pin_low(B6);//off fan
------Digital Inputs--------
Short story:
Here I was sneaking in the Photovore example and saw the Button_pressed() ... I was like were does that function come from...
It was declare in axon2.h ... there you can see, it used the D5 as input ... Looking at the datasheet were is that D5
... Going back to the axon2.h in the definition of the DDRD = 0b11010000 all make sense it was a button next to the 7 segment plus it was documented in there ... in the button of the axon2.h I created a funtion just like the Button_pressed() but with a different name and a different port obviously and bingo.
in the axon2.h "Careful, if you do something really wrong here ... things will not work properly and you will need to download it again ..."
all the way down of that file
// --------------- Start: define Button on the board ---------------------
// Original code by Admin @
www.societyofrobots.com#define button_pressed() pin_is_low(D5)
#define ReadInputH7() pin_is_high(H7) // You can declare as high or low ...The logic change thats all. "Active high or active low"
// --------------- End: define Button on the board ---------------------
now in your code you do this:
if (!ReadInputH7())
{
TheFamousDoSomethingFunction();
}
Now if you wanna see my complete code:
Video, Note -> "Is in Spanish"
Video0039.mp4 hardware.h :
//define servos, sensors, and other stuff here
//this keeps hardware separate from other code - making it easy to share/port
//declare libraries
#include "Sensors/Distance/Devantech/SRF05_Sonar.h"
#include "Sensors/Distance/Devantech/SRF04_Sonar.h"
#include "Sensors/Distance/Maxbotix/EZ1.h"
#include "Sensors/Distance/Ping/PingSonar.h"
#include "Sensors/Distance/Sharp/GP2.h"
//UART defines (name your UART)
#define GPS_UART UART0
#define USB_UART UART1
#define WIRELESS_UART UART2
#define OTHER_UART UART3
//UART baud defines (change baud rate)
#define GPS_BAUD (BAUD_RATE)9600
#define USB_BAUD (BAUD_RATE)115200
#define WIRELESS_BAUD (BAUD_RATE)38400
#define OTHER_BAUD (BAUD_RATE)38400
//UART define which uart to use
#define GPS_ACTIVATE &uart0SendByte
#define USB_ACTIVATE &uart1SendByte
#define WIRELESS_ACTIVATE &uart2SendByte
#define OTHER_ACTIVATE &uart3SendByte
#define USB_GET uart1GetByte()
Axon2_WebbotLib.c
// Example of using Axon for sonar and sharp IR
//uncomment the sensor you want to use
#define SONAR
//#define SHARP
#define RPRINTF_FLOAT
#include "sys/axon2.h"
#include "led.h"
#include "rprintf.h"
#include "hardware.h"
// This routine is called once only and allows you to do any initialisation
// Dont use any 'clock' functions here - use 'delay' functions instead
void appInitHardware(void){
// Set up the hardware UART to xmit the results
//initialize UART ports (see hardware.h to change baud/names)
uartInit(GPS_UART, GPS_BAUD); //UART0
uartInit(USB_UART, USB_BAUD); //USB
uartInit(WIRELESS_UART, WIRELESS_BAUD); //UART2
uartInit(OTHER_UART, OTHER_BAUD); //UART3
// Set rprintf to go to output
rprintfInit(USB_ACTIVATE);
//declare digital output pins
pin_make_output(B6);
pin_make_output(H6);
}
TICK_COUNT appInitSoftware(TICK_COUNT loopStart){
uartInit(USB_UART, USB_BAUD);
rprintf("\nc:\ message -> Axon initiated... MoltreX activated the security!!!\n\n Security online in 5 Seconds \n\n");
delay_ms(1000);//button debounce delay
rprintf("\nc:\ message -> 4 seconds\n\n");
delay_ms(1000);//button debounce delay
rprintf("\nc:\ message -> 3 seconds\n\n");
delay_ms(1000);//button debounce delay
rprintf("\nc:\ message -> 2 seconds\n\n");
delay_ms(1000);//button debounce delay
rprintf("\nc:\ message -> 1 seconds\n\n");
delay_ms(1000);//button debounce delay
rprintf("\nc:\ message -> Alarm Active ! ... System Online ...\n\n");
pin_high(B6);//Turning on the fan at the beginning
return 0;
}
int tempbyte;
// This routine is called repeatedly - its your main loop
TICK_COUNT appControl(LOOP_COUNT loopCount, TICK_COUNT loopStart){
tempbyte=USB_GET;//get a single character
if (tempbyte=='1') //to reset back everything and kill the noisy alarm
{
pin_high(B6);//on fan
pin_low(H6);//off Alarm
}
if (!ReadInputH7())//If the Ultra sonic sensor detects something
{
rprintf("\nAlarm is On !!!.\n\n");
pin_low(B6); //off fan
pin_high(H6); //on alarm
}
return 2000;//add delay
}
With the Digital Output you can turn On everything. Just remember if is grater than 5VDC with 20mA use a relay and with the digital output you can trigger a bigger output and so on relays in cascade if you need to trigger something big.
With the digital input the same, just remember the rules of I/O with the Axon 2 ... you don't want to fry the pin.
Thanks, I order a sabertooth, a compass and other sonar sensor ... maybe more questions coming.