Don't understand code line?!

This forum is dedicated to software development related to MultiWii.
It is not the right place to submit a setup problem.
Software download
Post Reply
User avatar
SoundMTB
Posts: 37
Joined: Tue Jul 26, 2011 8:17 am
Location: Germany Osnabrueck
Contact:

Don't understand code line?!

Post by SoundMTB »

Hi

can someone explain me the following Code line please:

Code: Select all

 vbatRawArray[(ind++)%8] = analogRead(V_BATPIN);


I realy not understand the (ind++)%8 espacialy the %8

regards
Oliver

timecop
Posts: 1880
Joined: Fri Sep 02, 2011 4:48 pm

Re: Don't understand code line?!

Post by timecop »

Ind is incremented, its value is limited to 0..7 (mod 8) to be used as array index.
You might want to give this a read
http://en.m.wikipedia.org/wiki/The_C_Pr ... g_Language

frank26080115
Posts: 26
Joined: Mon Jul 11, 2011 12:47 pm

Re: Don't understand code line?!

Post by frank26080115 »

%8 is there to ensure you never index out of the bounds of the array, which has only room for 8 elements, it's a common technique when you don't really care where in the array you are storing

User avatar
SoundMTB
Posts: 37
Joined: Tue Jul 26, 2011 8:17 am
Location: Germany Osnabrueck
Contact:

Re: Don't understand code line?!

Post by SoundMTB »

Many thank's

Now is clear

Oliver

KaiK
Posts: 58
Joined: Thu Jul 28, 2011 8:32 pm
Contact:

Re: Don't understand code line?!

Post by KaiK »


Post Reply