Author Topic: Arduino Nano Project to Digispark  (Read 3417 times)

kloeppi

  • Newbie
  • *
  • Posts: 2
Arduino Nano Project to Digispark
« on: February 17, 2015, 08:53:46 am »
Hi,

I am new to microcontrollers and created a first project with Arduino Nano.
Now I want to run this on a Digispark and I don't know how to connect the following components to the pins:

2 LED for digitalWrite  - prefered to P0 and P1
3 Poti for analogRead values only for delays - prefered to P2, P3, P4
1 Pushbutton for interrupt to awake board from sleep - prefered to P5

Can I connect this functions to these pins?

If so, how do I set the interrupt for connecting the pushbutton to P5.
For Arduino I set the interrupt with  "attachInterrupt(0, Ringing, LOW);" and have to connect the pushbutton to D2.

Do I have to use "FALLING" instead of "LOW" in the interrupt call (I did not found a Digispark example with "LOW")

That's the Arduino Code:

Code: [Select]
#include <avr/sleep.h>
#include <avr/power.h>

const int Bell = 2;
const int LiftHandset =  3;
const int Redial =  4;

int Startup = 1;

void Ringing(void)
{
  detachInterrupt(0);
}

void GoSleep(void)
{
  attachInterrupt(0, Ringing, LOW);
  delay(100);
  set_sleep_mode(SLEEP_MODE_PWR_DOWN);
  sleep_enable();
  sleep_mode();
  sleep_disable();
}

void setup()
{
  pinMode(Bell, INPUT);   
  pinMode(LiftHandset, OUTPUT);     
  pinMode(Redial, OUTPUT);
}

void loop()
{
  if (Startup == 0)
  {
    digitalWrite(LiftHandset, HIGH); 
    delay(analogRead(A0)/1.023*0.5);
    digitalWrite(Redial, HIGH);
    delay(analogRead(A1)/1.023*1.5);
    digitalWrite(Redial, LOW);
    delay(analogRead(A2)/1.023*15);
    digitalWrite(LiftHandset, LOW); 
  }
  else
  {
    Startup = 0;
  }
  GoSleep();
}

Thanks for any answer and please excuse my lousy english

kloeppi


kloeppi

  • Newbie
  • *
  • Posts: 2
Re: Arduino Nano Project to Digispark
« Reply #1 on: February 17, 2015, 09:59:59 am »
Tried "TinyPinChangeDemo" meanwhile but at compiling I get following error:

TinyPinChangeDemo.ino: In function 'void InterruptFunctionToCall()':
TinyPinChangeDemo.ino:103:57: error: 'TinyPinChange_GetPinEvent' was not declared in this scope
Fehler beim Übersetzen

Did not change anything in the code and "TinyPinChange.h" exists in the libraries folder.

Which Pin handles the interrupt 0 without pin change

kloeppi

PS: Can't try anymore because I have crashed the Digispark at testing and it can not be recognized by windows now