+ test sketches

This commit is contained in:
Rob Tillaart 2013-09-30 18:23:20 +02:00
parent 202deca306
commit 2f17d2c9f6
2 changed files with 135 additions and 0 deletions

View File

@ -0,0 +1,65 @@
//
// FILE: PCF8574_test.ino
// AUTHOR: Rob Tillaart
// DATE: 7-febr-2013
//
// PUPROSE: test PCF8574 library
//
#include "PCF8574.h"
#include <Wire.h>
PCF8574 PCF_01(0x38);
void setup()
{
Serial.begin(9600);
Serial.print("PCF8574_test version: ");
Serial.println(PCF8574_LIB_VERSION);
int x = PCF_01.read8();
Serial.print("Read ");
Serial.println(x, HEX);
delay(1000);
}
void loop()
{
Serial.println("HLT");
while (Serial.available() == 0);
switch(Serial.read())
{
case 'H': doHigh(); break;
case 'L': doLow(); break;
case 'T': doToggle(); break;
}
}
void doHigh()
{
PCF_01.write(4, HIGH);
int x = PCF_01.read8();
Serial.print("Read ");
Serial.println(x, HEX);
}
void doLow()
{
PCF_01.write(4, LOW);
int x = PCF_01.read8();
Serial.print("Read ");
Serial.println(x, HEX);
}
void doToggle()
{
PCF_01.toggle(4);
int x = PCF_01.read8();
Serial.print("Read ");
Serial.println(x, HEX);
}

View File

@ -0,0 +1,70 @@
//
// FILE: pcf8574_test.ino
// AUTHOR: Rob Tillaart
// DATE: 27-08-2013
//
// PUPROSE: demo
//
#include "PCF8574.h"
#include <Wire.h>
// adjust addresses if needed
PCF8574 PCF_38(0x38); // add switches to lines (used as input)
PCF8574 PCF_39(0x39); // add leds to lines (used as output)
void setup()
{
Serial.begin(115200);
Serial.println("\nTEST PCF8574\n");
uint8_t value = PCF_38.read8();
Serial.print("#38:\t");
Serial.println(value);
for (int i=0; i<255; i++)
{
PCF_39.write8(i);
delay(100);
}
PCF_39.write(0, 1);
for (int i=0; i<7; i++)
{
PCF_39.shiftLeft();
delay(100);
}
for (int i=0; i<7; i++)
{
PCF_39.shiftRight();
delay(100);
}
for (int i=0; i<8; i++)
{
PCF_39.write(i, 1);
delay(100);
PCF_39.write(i, 0);
delay(100);
}
for (int i=0; i<8; i++)
{
PCF_39.toggle(i);
delay(100);
PCF_39.toggle(i);
delay(100);
}
}
void loop()
{
// echos the lines
uint8_t value = PCF_38.read8();
PCF_39.write8(value);
delay(100);
}
//
// END OF FILE
//