/*
 * Project:    BinaryAdding_621task10
 * Author:     Jane-Maree Howard
 * Date:       Tuesday 30/08/2011
 * Platform:   Arduino 22
 * Purpose:    To demonstrate a function to add B0111 to a byte passed to it. 
 -             Called 256 times in loop() using 0-255 as the parameters. 
 * Operation:  Description: A function taking a byte as parameter adds a specific
 -                          binary number to it & returns a byte
 -             Declare: Function binaryAdd(bByte); bThisByte
 -             Setup(): Serial port @ 9600 baud; print bThisByte.
 -             Loop():  Adds byte B0111 to given byte 256 times                  
 */
byte  bThisByte  = B01011010; 
byte  bStoreByte;
void setup()   
{
  Serial.begin(9600);  //SM @ 9600baud 
  Serial.print("\nByte = \t");
  Serial.println(bThisByte, BIN);
  Serial.println();
}//end setup()
void loop()                     
{
  bStoreByte   = bThisByte;    // stores byte being operated on..
  for (int j=0; j<256; j++)
  {
    bThisByte  =+ BinaryAdd(bThisByte);
    Serial.print("Byte = \t");
    Serial.println(bThisByte, BIN);
    delay(100);
  }//for()
  Serial.print("\nStored: ");
  Serial.print(bStoreByte, BIN);
  Serial.println(",\t+ the 256 additions.\n");
  delay(2000);
}//end loop()
// BinaryAdd() - adds B00000111 to parameter
byte BinaryAdd(byte bByte)
{
  bByte = bByte + B00000111;
  return bByte;
}//BinaryAdd()
//END
The screen-shot on the right 
shows the start of the program.
Byte = 1011010
On the left, you can see the byte 
just above the stored byte - it's 
exactly the same value..
..& again, the same value, although  the program has gone through several more loop() cycles, as you 
can see by the position of the 
cursor at the right of the Serial 
Monitor.
The value remains 1011010.



 
No comments:
Post a Comment