a=1;
b=2;
if(portc.f1==1)
{
portd.f1=1; //100% Brightness
}
else
{
portd.f1=1; //pwm=50%
delay_ms(a);
portd.f1=0;
delay_ms(b);
}
Code C - [expand] 1 2 3 4 5 6 7 input_state = portc; // store the input value portd |= input_state // set to high the outputs that represent an input that has 1 portd ^= ~input_state; // invert the portd bits when the same bit in input_state is 0 , leaves bits with 1 in input_state unchanged delay_ms(a); portd ^= ~input_state; // invert the portd bits when the same bit in input_state is 0 delay_ms(b);
yesLet me get this right , by default all leds are dimmed, then when a sensor triggers then the led goes 100% and keeps this state until the previous or the next sensor are triggered?
yesWhat about the first and last sensor , they only have a sensor in one side (N1 has N2 and N7 has N6), so if N2 doesn't trigger N1 led will be 100% for ever?
how can it be implemented ?By comparing the new state with the previous state the LEDs can be updated as per an algorithm of your choice.
BigDog
Yes, by implementing the algorithms I have provided above.
BigDog
Use an external interrupt, all sensor inputs are OR'd and input into RB0, when ever the external interrupt is triggered, the new state of of the PORT sensor inputs is stored. By comparing the new state with the previous state the LEDs can be updated as per an algorithm of your choice.
BigDog
A bitwise AND with detect any object remaining stationary, Bs = 0b00000100. The mask produced from this operation can then be used to remove all stationary objects from the field.
The resulting bit fields, Bos = 0b01001000 and Bns = 0b10010000, can then be compared and analyzed to determine directionality of movement of the remaining two objects.
You can then take Bos, left shift by one and then bitwise AND with Bns, which will result in a bit field of the objects which moved to the left, Bl = 0b10010000.
You can then take Bos, right shift by one and then bitwise AND with Bns, which will result in a bit field of the objects which moved to the right, Br = 0b00000000.
BigDog
so polling should be likeDue to the nature of the sensor array and object traffic, polling would be a more viable solution in this case, rather external hardware interrupts.
BigDog
while(1)
{
if(PORTB != BNS) // Test PORTB against the latest new state
{
BOS = BNS; // Copy new state to old state
BNS = PORTB; // Copy entire PORTB to new state
Analyze(); // Analyze traffic movement
}
}
You can then take Bos, left shift by one and then bitwise AND with Bns, which will result in a bit field of the objects which moved to the left, Bl = 0b10010000.
You can then take Bos, right shift by one and then bitwise AND with Bns, which will result in a bit field of the objects which moved to the right, Br = 0b00000000.
BigDog
we should combine these two and output to the output port, isnt it ?
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?