I am Xiaobai , Make some small things at home during the summer vacation . What I want to share with you this time is based on STM32F103 The production of the tracking car .( Two wheels )

Main hardware : board ,L298N, electric machinery ,4 Tracking modules, etc

Don't talk much , Dry goods first .

XJ.c

#include "XJ.h"// Trace file
#include "stm32f10x.h"
void XJ_Init(void)
{
        GPIO_InitTypeDef GPIO_InitStructure;
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);
    
    
    GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IN_FLOATING;// Configuration as floating input , The pin level can be read
    GPIO_InitStructure.GPIO_Pin=GPIO_Pin_4|GPIO_Pin_5|GPIO_Pin_6|GPIO_Pin_7;
    GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
    GPIO_Init(GPIOA,&GPIO_InitStructure);
        GPIO_SetBits(GPIOB,GPIO_Pin_4|GPIO_Pin_5|GPIO_Pin_6|GPIO_Pin_7);
    // Configure all pins connected to the trace module to high level , When a black line is detected , The pin will return to the high level
}

main.c( Only some key codes are posted )

while(1){

 

if(KEY0==0)//Èç¹û°´¼ü0±»°´Ï£¬¿ªÆôÑ­¼£Ä£Ê½
         {
             while(1)//
             {
                 XJ1=GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_4);//
                 XJ2=GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_5);
                 XJ3=GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_6);
                 XJ4=GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_7);

             if((XJ1==1|XJ2==1)&&(XJ3==0&&XJ4==0))
             {
            
                 turnleft();
            delay_ms(150);
                 
             }
            else if((XJ3==1|XJ4==1)&&(XJ1==0&&XJ4==0))//
             {
                 
                 turnright();
                 delay_ms(150);
                 
             }
             else if((XJ1==1&&XJ2==1)&&(XJ3==1&&XJ4==1))// High level detected on all four pins , stop it
             {
            
                 stop();
                              delay_ms(150);

                 
             }
             else if((XJ2==0&&XJ1==0)&&(XJ4==0&&XJ3==0))
             {
                
                 forward();            
        delay_ms(200);

             }
         }
     }

Personal summary :

Before making things , Be sure to check the function introduction and usage of various modules .( Xiaobai, I bought two different modules , The result is that the program can not run smoothly , It took a lot of time to modify , Finally, I was forced to check the user manual of the module ) secondly , We must insist , Confusion of ideas ( Especially for beginners like Xiaobai ) be not afraid of , The biggest fear is not to solve it , You can do something that has nothing to do with electronics , I'll come back later to think again . also , Make use of it MDK Software simulation function of . Finally, be good at rewriting the program , How to make the program more efficient , How to rewrite a part of your project online .

I made a promise for ten years , Just for the most beautiful meeting .

I'm a Siberian cockroach , friend , See you next time .

 

Technology
©2019-2020 Toolsou All rights reserved,
VUE+Canvas Achieve desktop Pinball brick elimination games C/C++ Memory model 2019PHP Interview questions ( Continuously updated )PHPspringboot2 Separation of front and rear platforms ,token Put in header Pit for verification Vue SpringBoot conduct Excel download element-ui Step on pit record 45 The 12-year-old programmer was turned down , Is the workplace wrong ?Python Web frame Pandas Fundamentals of statistical analysis _ data processing (DataFrame Common operations )Java Misunderstanding —— Method overloading is a manifestation of polymorphism ?