mmahfuj
Junior Member level 2
- Joined
- May 31, 2012
- Messages
- 23
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,281
- Location
- Chittagong,Bangladesh
- Activity points
- 1,491
counter=counter;
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 while (1){ // assuming sensors are variables sA and sB, and lights switch is sL unsigned int People=0; // counter for people inside the room char AllowNextCount=0; // boolean indicating if allowing next count or not char InOut; // 1 = entering; -1 = exiting if ((sA==0) && (sB==1)){ // entering InOut = 1; } if ((sA==1) && (sB==0)){ // exiting InOut = -1; } if ((sA==1) && (sB==1) && (AllowNextCount==1)){ // only when both sensors are touched validate the people counter People += InOut; if (People > 0) sL = 1; // Turn/keep lights on as long as People greather than 0 else sL = 0; // otherwise, turn them off // count once then block counting until the same person has finished entering/exiting AllowNextCount=0; } if ((sA==0) && (sB==0)){ // it gets 0;0 only when someone has finished entering/exiting // or at turn on; so now allow to counting again AllowNextCount=1; } }
// assuming sensors are variables sA and sB, and lights switch is sL
unsigned int People=0; // counter for people inside the room
char AllowNextCount=0; // indicating if allowing next count or not
char InOut; // 1 = entering; -1 = exiting
void main()
{
TRISB=0b11000000;
TRISC=0;
portb=0;
while (1)
{
if ((RB6_bit==0) && (RB7_bit==1))
{
delay(100);
if ((RB6_bit==0) && (RB7_bit==1))
// entering
InOut = 1;
}
}
if ((RB6_bit==1) && (RB7_bit==0))
{
delay(100);
if ((RB6_bit==1) && (RB7_bit==0)) {
// exiting
InOut = -1;
}
}
if ((RB6_bit==0) && (RB7_bit==0) && (AllowNextCount==1)){
// only when both sensors are touched validate the people counter
People += InOut;
if (People > 0)
RC0_bit = 1; // Turn/keep lights on as long as People greater than 0
else
RC0_bit = 0; // otherwise, turn them off
// count once then block counting until the same person has finished entering/exiting
AllowNextCount=0;
}
if ((RB6_bit==0) && (RB7_bit==0)){
// it gets 0;0 only when someone has finished entering/exiting
// or at turn on; so now allow to counting again
AllowNextCount=1;
}
}
}
b2 is on first and then b1 is on then then decrease the number but light will be off if there is none in the room
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 #include <htc.h> __CONFIG(0x3FF1); #ifndef _XTAL_FREQ #define _XTAL_FREQ 4000000 #endif // HD44780 controller based LCD display drivers for PIC10/12/16 // Driver is a personal work I made, you can download the LCD driver from: // [url]https://www.edaboard.com/blog/1817/[/url] #include "HD44780.h" #include "HD44780.c" #define sA RA0 #define sB RA1 #define sL RA2 void main(void){ // TRIS registers TRISA = 0x03; // RA0 and RA1 are inputs TRISB = 0x00; // assuming sensors are variables sA and sB, and lights switch is sL unsigned int People=0; // counter for people inside the room char AllowNextCount=0; // boolean indicating if allowing next count or not short int InOut; // 1 = entering; -1 = exiting // Initializing LCD LCD_Initialize(); // Set data on display the first time LCD_Clear(); LCD_WriteString("Counter: "); LCD_WriteNumber(People); LCD_WriteString("\nLights: "); LCD_WriteNumber(sL); while (1){ if ((sA==0) && (sB==1)){ // entering InOut = 1; } if ((sA==1) && (sB==0)){ // exiting InOut = -1; } if ((sA==1) && (sB==1) && (AllowNextCount==1)){ // only when both sensors are touched validate the people counter People += InOut; if (People > 0) sL = 1; // Turn/keep lights on as long as People greather than 0 else sL = 0; // otherwise, turn them off // count once then block counting until the same person has finished entering/exiting AllowNextCount=0; // Update data on display LCD_Clear(); LCD_WriteString("Counter: "); LCD_WriteNumber(People); LCD_WriteString("\nLights: "); LCD_WriteNumber(sL); } if ((sA==0) && (sB==0)){ // it gets 0;0 only when someone has finished entering/exiting // or at turn on; so now allow to counting again AllowNextCount=1; } } }
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?