Pages: [1]   Go Down
Author Topic: About digitalWrite  (Read 372 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello to everybody First of all I apologise for my bad english
I have a question about the  use of digitalWrite
I have a matrix led and i work with this code (Which is work fine)
------------------------------------------------------------------------------------------
Code:
int delayTime= 80;        // 1mS increments before next LED
int delayStep;
int ledPin, col, row ;

void setup()               // run once, when the sketch starts
{
for (ledPin=2; ledPin <=12; ledPin++)   // Standard setup for LMP
{ pinMode(ledPin, OUTPUT);             // sets the digital pin as output
digitalWrite(ledPin,(ledPin <=7)) ;     // and sets all OFF
}
}

void loop()                                     // run over and over again
/* Map PORTB == D8:D13
   PORTD == D0:D7
   Our output: col::D7:D2
   (8-col) -ve (LOW)
   while row::D8:D13 +ve
   (row+7) +ve (HIGH)
*/
{
for (row=1; row <=5; row++)
{                                            // Vertical: left to right
digitalWrite(row + 7,HIGH);    // Enable entire ROW
for (col=1; col <=6; col++)
{                                           // then one pixel per col
digitalWrite(8- col,LOW);      // gets turned on
delay(delayTime);                 // for a moment
digitalWrite(8- col,HIGH);     // then OFF before next one
}                            
digitalWrite(row + 7, LOW);   // We're done with this row
}
.........................
------------------------------------------------------------------------------------------------------------

I learn in arduino reference quide that the syntax of digitalWrite is digitalWrite (pin, value)
The value is possible to be HIGH or LOW
But in the above code the value is numeric (if understand well)

1st question : What value take the expression digitalWrite(ledPin,(ledPin <=7)
i suppose that take every cycle of "if" the value
1st cycle > digitalWrite(1, 1)
2nd cycle > digitalWrite(2, 2)
3nd cycle > digitalWrite(3, 3)
4th cycle > digitalWrite(4, 4)
5th cycle > digitalWrite(5, 5)
6th cycle > digitalWrite(6, 6)
7th cycle > digitalWrite(7, 7)
and after in 8th cycle what?
 
2nd queston : When the value is numeric the pin is HIGH or LOW?

The above code is from http://www.instructables.com/id/Build-a-low-cost-scrolling-LED-display-for-your-A/step6/A-test-sketch/

Thanks
babis
« Last Edit: July 01, 2011, 04:55:23 pm by bmagigr » Logged

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

Quote
What value take the expression digitalWrite(ledPin,(ledPin <=7)
If ledPin <= 7 then the value written is HIGH, otherwise it is LOW.
The value of HIGH is 1, the value of LOW is 0 (zero)
So, if ledPin is 4
digitalWrite(4, 1);
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.

Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thank you for your reply  smiley
Logged

Pages: [1]   Go Up
Jump to: