Advertisement
Guest User

Untitled

a guest
Jul 24th, 2017
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. int PhotoArray[7] = {0,0,0,0,0,0,0};
  2. //status of each PhotoTransistor stored here
  3. int TransistorArray[7] = {8,14,6,4,2,0,12};
  4. //TransistorArray relates the respective ADC/Transistor channel to the index of IRs.
  5. for(int i = 0; i < 7; i++){
  6. setIR(i);
  7. for(int j = 0; j < 1000; j++){} //garbage loop for delay
  8. PhotoArray[i] = PollIR(TransistorArray[i]);
  9. trace_printf("%u ", PhotoArray[i]);//in theory I can remove this, not sure what happens in practice.
  10. if(!PhotoArray[i])//sets display LED when on tape
  11. setLED(i);
  12. if(PhotoArray[i])//resets display LED when not on tape
  13. resetLED(i);
  14. for(int j = 0; j < 1000; j++){} //garbage loop for delay
  15. }
  16. //case: on track, middle 3 transistors read tape
  17. if(!PhotoArray[2] && !PhotoArray[3] && !PhotoArray[4]){
  18. //reset reverse pins, L&R motors
  19. HAL_GPIO_WritePin( GPIOB, GPIO_PIN_4 , GPIO_PIN_RESET );
  20. HAL_GPIO_WritePin( GPIOE, GPIO_PIN_6 , GPIO_PIN_RESET );
  21. //set forward pins, L&R motors
  22. HAL_GPIO_WritePin( GPIOB, GPIO_PIN_6 , GPIO_PIN_SET );
  23. HAL_GPIO_WritePin( GPIOB, GPIO_PIN_8 , GPIO_PIN_SET );
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement