Moderators: adafruit_support_bill, adafruit
if (valF>=thresHold && valFenabled) { // waits for force sensor to equal or pass pressure threshold and then:
valFenabled = 0; //signal that button has been pressed before
delay(1000); //
digitalWrite(RedPin, LOW); //
digitalWrite(GreenPin, LOW); //
delay(1000); //
digitalWrite(RedPin, HIGH); //
digitalWrite(GreenPin, HIGH); //
delay(1000); //
valSenabled = 1;
}
if (valS == HIGH && valSenabled) { // waits for switch to be pressed, and then:
valSenabled = 0; //signal that button has been pressed before
delay(1000);
digitalWrite(GreenPin, LOW);
digitalWrite(RedPin, LOW);
delay(400);
digitalWrite(GreenPin, HIGH);
digitalWrite(RedPin, HIGH);
delay(400);
valFenabled = 1;
}
}adafruit_support wrote:As mentioned in the link I posted earlier, the only way to wake up from a sleep is via interrupt. The second set of example code in the link shows how to wake up based on an interrupt on pin 2.
The question then is how to trigger an interrupt on pin 2 with a force sensor: That will depend on what kind of force sensor you are talking about. If it is an FSR, you enable the pullup resistor on pin 2 and connect the FSR between pin 2 and GND. When there is sufficient pressure on the FSR, it will pull pin 2 low and generate the interrupt.
Please can you explain to me what you mean by " enable the pullup resistor"? .
adafruit_support wrote:Please can you explain to me what you mean by " enable the pullup resistor"? .
See the paragraph titled "Pullup Resistors" here: http://arduino.cc/en/Tutorial/DigitalPins
zajebiscie wrote:For example what if i wanted to use FSR at pin 2 connected to ground and i want my arduino to be active without grouding pin 12 for momentary for the arduino to fall asleep, how can i do that in the example code you provided, so i do not have to go through that hassel making arduino to go to idle?
driverblock wrote:zajebiscie wrote:For example what if i wanted to use FSR at pin 2 connected to ground and i want my arduino to be active without grouding pin 12 for momentary for the arduino to fall asleep, how can i do that in the example code you provided, so i do not have to go through that hassel making arduino to go to idle?
That's what the first example does. Call SleepNow whenever you want to go to sleep. Ground pin 2 to wake up.
zajebiscie wrote:Please could you tell me how long it will take the arduino to go to sleep when it is on idle mode, and how can we reset the time to our own time after FSR is not in use?
driverblock wrote:zajebiscie wrote:Please could you tell me how long it will take the arduino to go to sleep when it is on idle mode, and how can we reset the time to our own time after FSR is not in use?
When you call SleepNow, it will only take a few microseconds for the arduino to go to sleep.
I don't understand what you mean about resetting the time. Is there a clock associated with this project?
#include <avr/interrupt.h>
#include <avr/power.h>
#include <avr/sleep.h>
#include <avr/io.h>
//
void setup(void)
{
DDRD &= B00000011; // set Arduino pins 2 to 7 as inputs, leaves 0 & 1 (RX & TX) as is
DDRB = B00000000; // set pins 8 to 13 as inputs
PORTD |= B11111100; // enable pullups on pins 2 to 7
PORTB |= B11111111; // enable pullups on pins 8 to 13
pinMode(13,OUTPUT); // set pin 13 as an output so we can use LED to monitor
digitalWrite(13,HIGH); // turn pin 13 LED on
}
//
void loop(void)
{
// Stay awake for 1 second, then sleep.
// LED turns off when sleeping, then back on upon wake.
delay(100);
sleepNow();
}
//
void sleepNow(void)
{
/* Now is the time to set the sleep mode. In the Atmega8 datasheet
* http://www.atmel.com/dyn/resources/prod_documents/doc2486.pdf on page 35
* there is a list of sleep modes which explains which clocks and
* wake up sources are available in which sleep modus.
*
* In the avr/sleep.h file, the call names of these sleep modus are to be found:
*
* The 5 different modes are:
* SLEEP_MODE_IDLE -the least power savings
* SLEEP_MODE_ADC
* SLEEP_MODE_PWR_SAVE
* SLEEP_MODE_STANDBY
* SLEEP_MODE_PWR_DOWN -the most power savings
*
* the power reduction management <avr/power.h> is described in
* http://www.nongnu.org/avr-libc/user-manual/group__avr__power.html
*/
// Set pin 2 as interrupt and attach handler:
attachInterrupt(0, pinInterrupt, LOW);
delay(100);
//
// Choose our preferred sleep mode:
set_sleep_mode(SLEEP_MODE_IDLE);
//
// Set sleep enable (SE) bit:
sleep_enable();
power_adc_disable();
power_spi_disable();
power_timer0_disable();
power_timer1_disable();
power_timer2_disable();
power_twi_disable();
//
// Put the device to sleep:
digitalWrite(13,LOW); // turn LED off to indicate sleep
sleep_mode();
//
// Upon waking up, sketch continues from this point.
sleep_disable();
digitalWrite(13,HIGH); // turn LED on to indicate awake
}
//
void pinInterrupt(void)
{
detachInterrupt(0);
}Users browsing this forum: No registered users and 13 guests