Show Posts
Pages: [1] 2 3 ... 14
1  Using Arduino / Programming Questions / Re: How to step back to loop() during an interrupt on: October 18, 2013, 11:27:59 pm
Thank you so much, Jack
I changed sinex() to this
Code:
void sinex(){
  x+=0.00001;
  a=255*abs(sin(x*(180/PI)));
  analogWrite(0, a);
  if(x>= PI){
    x=0;
  }
}
and it's working perfectly! I'll change the flash() into something that sets the intensity according to an analogue input from a pot.
Thanks again!
2  Using Arduino / Programming Questions / Re: How to step back to loop() during an interrupt on: October 18, 2013, 10:49:57 pm
Thanks.
I changed the code, without the interrupts. When I press the button, it goes from flash() to sinex(), but when I press the button again, it doesn't jump back to flash() Why is this?
Code:
boolean mode=false;
long previousMillis=0;
int state=LOW;
int a=0;
void sinex(){
  for (float x=0;x<PI;x=x+0.00001){
    a=255*abs(sin(x*(180/PI)));
    analogWrite(0, a);
  }
}
void flash(){
  unsigned long currentMillis=millis();
  if(currentMillis-previousMillis>1000){
    previousMillis=currentMillis;
    if(state==LOW){
      state=HIGH;
    }
    else{
      state=LOW;
    }
    digitalWrite(0, state);
  }
}
void setup(){
  pinMode(0,OUTPUT);
  pinMode(2, INPUT);
  digitalWrite(2, HIGH);

}
void loop(){
  if(digitalRead(2)==LOW){
    delay(20);  //debounce
    if(digitalRead(2)==HIGH){
      mode=~mode;
    }
  }
  if(mode==false){
    flash();
  }
  else{
    sinex();
  }
}
3  Using Arduino / Installation & Troubleshooting / Re: Something wrong with my Arduino on: October 18, 2013, 09:40:50 pm
Haha yeah I think I burned the bootloader with an UNO as well. That was a while ago...
Good luck with your Arduino projects! smiley
4  Using Arduino / Programming Questions / Re: How to step back to loop() during an interrupt on: October 18, 2013, 09:41:23 am
I see. I thought it would be easier to write the program with the interrupts. Should I stop using interrupts?
5  Using Arduino / Programming Questions / How to step back to loop() during an interrupt on: October 18, 2013, 09:05:55 am
Hi, I am trying to make a mood lamp with an attiny 45. I want the led to flash, then when I press a button, the intensity goes up and down as in a sine wave, then when the button is pressed again, it goes back to flashing.
This is my code:
Code:
int a=1;
void sinex(){
  for (float x=0;x<PI;x=x+0.00001){
    a=255*abs(sin(x*(180/PI)));
    analogWrite(0, a);
    // delay(30);
  }
}
void flash(){
  digitalWrite(0, HIGH);
  delay(1000);
  digitalWrite(0, LOW);
  delay(1000);
}
void inter(){
  if(digitalRead(2)==HIGH){
    while(digitalRead(2)==HIGH){
      sinex();
    }
  }
}
void setup(){

  pinMode(0,OUTPUT);
  pinMode(2, INPUT);
  digitalWrite(2, HIGH);
  attachInterrupt(0, inter, LOW);
}
void loop(){
  flash();
}
After I press the button, the led goes from flashing to sine-wave brightness. But when I press it again, nothing happens. Can anybody please tell me how to make it go back to loop()? Thanks a lot!
6  Using Arduino / Programming Questions / Re: Expexted unqualified-id before string constant on: September 14, 2013, 07:56:49 pm
Thanks a lot, this works.
Code:
volatile int inV = 0;
volatile int a = 0;
volatile int val=0;
void setup(){
  attachInterrupt(0,set, LOW);
}
void loop(){
  inV=analogRead(A0);
  inV=map(inV, 0, 1023, 0, 255);
  analogWrite(13, val);
}
void set(){
  a++;
  if(a==3){
    a=0;
  }
  if(a==0){
    val=255;
  }
  if(a==1){
    val=inV;
  }
  if(a==2){
    return;
  }
}
7  Using Arduino / Programming Questions / Re: Expexted unqualified-id before string constant on: September 14, 2013, 07:51:58 pm
Hi, I'm really sorry about that, I didn't mean to make anybody look like an idiot. Can anybody please help me?
8  Using Arduino / Programming Questions / Re: Expexted unqualified-id before string constant on: September 14, 2013, 07:27:03 pm
Hi, really sorry. I changed the code and the error message.
9  Using Arduino / Programming Questions / Re: Expexted unqualified-id before string constant on: September 14, 2013, 07:16:52 pm
Sorry, I must have fixed that problem on the sketch, I didn't see it on the sketch in my computer. I think it was when I changed the code on the thread I must have mad a mistake.
10  Using Arduino / Programming Questions / Re: Expexted unqualified-id before string constant on: September 14, 2013, 07:07:03 pm
Hi, I don't see any non-matching curly braces. Could it be something else?
11  Using Arduino / Programming Questions / Re: Expexted unqualified-id before string constant on: September 14, 2013, 06:37:43 pm
Hi, I changed the = into ==, and I still get the error. Why is that?
12  Using Arduino / Programming Questions / Expexted unqualified-id before string constant on: September 14, 2013, 08:00:59 am
Hi, I'm trying to make a mood lamp, this is the code:
Code:
void setup(){
  attachInterrupt(0,ISR, LOW);
  volatile int inV = 0;
  volatile int a = 0;
  volatile int val=0;
}
void loop(){
  inV=analogRead(A0);
  inV=map(inV, 0, 1023, 0, 255);
  analogWrite(13, val);
}
void ISR(){
  a++;
  if(a=3){
    a=0;
  }
  if(a=0){
    val=255;
  }
  if(a=1){
    val=inV;
  }
  if(a=2){
    return;
  }
}
and I keep getting this error:
Quote










sketch_sep14a:4: error: expected unqualified-id before string constant
sketch_sep14a:4: error: expected unqualified-id before 'void'
sketch_sep14a:4: error: expected `)' before 'void'
sketch_sep14a.ino: In function 'void setup()':
sketch_sep14a:2: error: 'ISR' was not declared in this scope
sketch_sep14a.ino: In function 'void loop()':
sketch_sep14a:8: error: 'inV' was not declared in this scope
sketch_sep14a:10: error: 'val' was not declared in this scope
sketch_sep14a.ino: At global scope:
sketch_sep14a:12: error: expected unqualified-id before string constant
sketch_sep14a:12: error: expected unqualified-id before 'void'
sketch_sep14a:12: error: expected `)' before 'void'

can anybody tell me why? Thank you so much!
13  Using Arduino / Programming Questions / Re: What does this mean? on: March 01, 2013, 07:32:17 pm
Thank you! I uploaded and now it works. It recognizes my Mega as an R3 now smiley
14  Community / Website and Forum / Re: Forum Website Down on: February 22, 2013, 11:17:00 am
Woohoo! Site's back! Great job dev. team! Thank you so much!
15  Using Arduino / Programming Questions / Re: What does this mean? on: February 21, 2013, 05:54:49 am
avrdude does not support atmegau2. What do I do in this case? Is there a configuration file for avrdude? Or is there an other program I can use?
Pages: [1] 2 3 ... 14