Pages: [1]   Go Down
Author Topic: why won't it add?  (Read 881 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Sr. Member
****
Karma: 0
Posts: 297
Arduino rocks!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

here is code:
Code:
 int rgbV = 26;
  int pV = 13;
  int V = 0;
  int V2 = 0;
  
void setup() {
    
  #define p1 13    
  #define p2 9
  #define p3 5
  #define p4 22
  #define p5 12
  #define p6 8
  #define p7 4
  #define p8 23
  #define p9 11
  #define p10 7
  #define p11 3
  #define p12 24
  #define p13 10
  #define p14 6
  #define p15 2
  #define p16 25
  #define r1 26
  #define g1 27
  #define b1 28  
  #define r2 29  
  #define g2 30  
  #define b2 31  
  #define r3 32  
  #define g3 33  
  #define b3 34  
  #define r4 35  
  #define g4 36  
  #define b4 37
  
  pinMode(22, OUTPUT);
  pinMode(23, OUTPUT);
  pinMode(24, OUTPUT);
  pinMode(25, OUTPUT);
  pinMode(2, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(7, OUTPUT);
  pinMode(8, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(11, OUTPUT);
  pinMode(12, OUTPUT);
  pinMode(13, OUTPUT);
  pinMode(26, OUTPUT);
  pinMode(27, OUTPUT);
  pinMode(28, OUTPUT);
  pinMode(29, OUTPUT);
  pinMode(30, OUTPUT);
  pinMode(31, OUTPUT);
  pinMode(32, OUTPUT);
  pinMode(33, OUTPUT);
  pinMode(34, OUTPUT);
  pinMode(35, OUTPUT);
  pinMode(36, OUTPUT);
  pinMode(37, OUTPUT);
}

void loop() {
  digitalWrite(rgbV, HIGH);  
  digitalWrite(p1, HIGH);
  delay(500);              
  digitalWrite(rgbV, LOW);
  digitalWrite(p1, LOW);
  delay(500);      
  if (rgbV = 37) {
    rgbV = 26;
  }
  else {
    [glow]++rgbV;[/glow]  }
}
Logged

As always... Thanks for posting!!!

North Yorkshire, UK
Offline Offline
Faraday Member
**
Karma: 104
Posts: 5531
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

define's go outside setup(){}
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 641
Posts: 50351
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
if (rgbV = 37) {
This assigned the value 37 to rgbV. It did not compare the value in rgbV to 37. The comparison operator (==) would have done that.
Logged

Global Moderator
Netherlands
Online Online
Shannon Member
*****
Karma: 223
Posts: 13906
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
if (rgbV = 37) {
    rgbV = 26;
  }
  else {
    ++rgbV;  }
PaulS is completely right,  
The assignment gives rgbV the value 37. In the if statement all values not equal to zero are evaluated true so the statement rgbV =26 will be executed all the time.
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 309
Posts: 26505
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
define's go outside setup(){}
#defines can go just about anywhere you like as long as they're before any references to them.
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

North Yorkshire, UK
Offline Offline
Faraday Member
**
Karma: 104
Posts: 5531
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
#defines can go just about anywhere you like as long as they're before any references to them.
You learn something new every day smiley
Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 361
Posts: 17303
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
You learn something new every day  

Not me, at my age I'm lucky if I learn something new once a week. And yes, my lawn is off limits.  smiley-wink

Lefty
Logged

Pages: [1]   Go Up
Jump to: