Hi, i'm new to Arduino, and this programming language. I`m trying too learn how too use a function.
It looks like i cant change the integer "t". Ive done some researche and the try and failed method, without luck. It works perfectly directly in void loop.
Does anyone know whats wrong with my program? Probably something obvious, but i`m not that good yet . But im getting there
unsigned long previousmillis = 0;
unsigned long currentmillis = millis();
int t = 0;
void setup () {
 pinMode (13, OUTPUT);
 Serial.begin (9600);
 digitalWrite (13, LOW);
Â
}
void blinkLED (int blinkpaa, int blinkav) {
Â
 unsigned long currentmillis = millis();
 Serial.println (currentmillis);
Â
 if (currentmillis - previousmillis >= blinkav & t==0) {
  previousmillis = currentmillis;
  digitalWrite (13, HIGH);
  int t = 1;
 }
 if (currentmillis - previousmillis >= blinkpaa & t==1) {
  previousmillis = currentmillis;
  digitalWrite (13, LOW);
  int t = 0;
 }
}
void loop () {
Â
 blinkLED(1000,1000);
Â
}
[code]
I thought i was changing the one variable named "t".
By defining two more?
if (currentmillis - previousmillis >= blinkav & t==0) {
previousmillis = currentmillis;
digitalWrite (13, HIGH);
t = 1; // Diddle with the ONE global variable.
}
if (currentmillis - previousmillis >= blinkav & t==0) {
previousmillis = currentmillis;
digitalWrite (13, HIGH);
t = 1;
}
if (currentmillis - previousmillis >= blinkpaa & t==1) {
I can't see how bitwise ANDing true and true, true and false, false and true, or false and false is what you want.
Logical ANDing (&&) is a different story...
As said befor, im new to this and i`m still learning. I needed something to decide which "if" to go with. So this was the best I could come up with my limited knowlegde of different commands and functions
If you have improvements or other solutions i`d be happy to know
if (currentmillis - previousmillis >= blinkav & t==0) {
previousmillis = currentmillis;
digitalWrite (13, HIGH);
t = 1;
}
if (currentmillis - previousmillis >= blinkpaa & t==1) {
I can't see how bitwise ANDing true and true, true and false, false and true, or false and false is what you want.
Logical ANDing (&&) is a different story...
As said befor, im new to this and i`m still learning. I needed something to decide which "if" to go with. So this was the best I could come up with my limited knowlegde of different commands and functions
If you have improvements or other solutions i`d be happy to know
What he's (cryptically) trying to tell you is that & and && are different operators. & is a bitwise operator and not what you want here. && works with boolean values and is the thing you need here. Look in the reference section for more information
Okay, so I think i got the differens between "&" and "&&". The "&" is on a "binary level" , and "&&" is what I meant to use. I guess the same goes for OR, "|" and "||".
I guess it worked in my code because, true & true = true. And thats why IF were fulfilled?
Here are some examples of my idea of what this is:
AND
void setup () {
Serial.begin (9600);
int a = 13; // 1101 1*2`3(=8) + 1*2`2(=4) + 0*2`1(=0) + 1*2`0(=1) = 13
int b = 11; // 1011 1*2`3(=8) + 0*2`2(=0) + 1*2`1(=2) + 1*2`0(=1) = 11
int c = a & b; // 1001 1*2`3(=8) + 0*2`2(=0) + 0*2`1(=0) + 1*2`0(=1) = 9
Serial.println (c);
}
void loop () {
// Ikke bruk for program
}
OR
void setup () {
Serial.begin (9600);
int a = 13; // 1101 1*2`3(=8) + 1*2`2(=4) + 0*2`1(=0) + 1*2`0(=1) = 13
int b = 11; // 1011 1*2`3(=8) + 0*2`2(=0) + 1*2`1(=2) + 1*2`0(=1) = 11
int c = a | b; // 1111 1*2`3(=8) + 1*2`2(=4) + 1*2`1(=2) + 1*2`0(=1) = 15
Serial.println (c);
}
void loop () {
// Ikke bruk for program
}