diff --git a/Code/C_Code/05.1.1_ColorfulLED/ColorfulLED.c b/Code/C_Code/05.1.1_ColorfulLED/ColorfulLED.c index 92ffe82..7722654 100644 --- a/Code/C_Code/05.1.1_ColorfulLED/ColorfulLED.c +++ b/Code/C_Code/05.1.1_ColorfulLED/ColorfulLED.c @@ -42,7 +42,7 @@ int main(void) b=random()%100; //get a random in (0,100) setLedColor(r,g,b);//set random as the duty cycle value printf("r=%d, g=%d, b=%d \n",r,g,b); - delay(300); + delay(1000); } return 0; } diff --git a/Code/C_Code/20.1.1_I2CLCD1602/I2CLCD1602.c b/Code/C_Code/20.1.1_I2CLCD1602/I2CLCD1602.c index 4ab4e23..0431a72 100644 --- a/Code/C_Code/20.1.1_I2CLCD1602/I2CLCD1602.c +++ b/Code/C_Code/20.1.1_I2CLCD1602/I2CLCD1602.c @@ -2,17 +2,17 @@ * Filename : I2CLCD1602.c * Description : Use the LCD display data * Author : www.freenove.com -* modification: 2019/12/27 +* modification: 2020/07/23 **********************************************************************/ #include #include #include +#include #include #include #include -//#define pcf8574_address 0x27 // default I2C address of Pcf8574 -#define pcf8574_address 0x3F // default I2C address of Pcf8574A +int pcf8574_address = 0x27; // PCF8574T:0x27, PCF8574AT:0x3F #define BASE 64 // BASE any number above 64 //Define the output pins of the PCF8574, which are directly connected to the LCD1602 pin. #define RS BASE+0 @@ -45,7 +45,24 @@ void printDataTime(){//used to print system time timeinfo = localtime(&rawtime);//convert to local time printf("%s \n",asctime(timeinfo)); lcdPosition(lcdhd,0,1);// set the LCD cursor position to (0,1) - lcdPrintf(lcdhd,"Time: %02d:%02d:%02d", timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec); //Display system time on LCD + lcdPrintf(lcdhd,"Time:%02d:%02d:%02d",timeinfo->tm_hour,timeinfo->tm_min,timeinfo->tm_sec); //Display system time on LCD +} +int detectI2C(int addr){ + int _fd = wiringPiI2CSetup (addr); + if (_fd < 0){ + printf("Error address : 0x%x \n",addr); + return 0 ; + } + else{ + if(wiringPiI2CWrite(_fd,0) < 0){ + printf("Not found device in address 0x%x \n",addr); + return 0; + } + else{ + printf("Found device in address 0x%x \n",addr); + return 1 ; + } + } } int main(void){ int i; @@ -53,7 +70,16 @@ int main(void){ printf("Program is starting ...\n"); wiringPiSetup(); - + if(detectI2C(0x27)){ + pcf8574_address = 0x27; + }else if(detectI2C(0x3F)){ + pcf8574_address = 0x3F; + }else{ + printf("No correct I2C address found, \n" + "Please use command 'i2cdetect -y 1' to check the I2C address! \n" + "Program Exit. \n"); + return -1; + } pcf8574Setup(BASE,pcf8574_address);//initialize PCF8574 for(i=0;i<8;i++){ pinMode(BASE+i,OUTPUT); //set PCF8574 port to output mode diff --git a/Code/Python_Code/05.1.1_ColorfulLED/ColorfulLED.py b/Code/Python_Code/05.1.1_ColorfulLED/ColorfulLED.py index 7d971b7..e512668 100644 --- a/Code/Python_Code/05.1.1_ColorfulLED/ColorfulLED.py +++ b/Code/Python_Code/05.1.1_ColorfulLED/ColorfulLED.py @@ -35,7 +35,7 @@ def loop(): b=random.randint(0,100) setColor(r,g,b) #set random as a duty cycle value print ('r=%d, g=%d, b=%d ' %(r ,g, b)) - time.sleep(0.3) + time.sleep(1) def destroy(): pwmRed.stop() diff --git a/Tutorial.pdf b/Tutorial.pdf index 21476e4..e6677c8 100644 Binary files a/Tutorial.pdf and b/Tutorial.pdf differ