首页/作品列表/智能避障小车
智能避障小车
5620 0
主要内容
设计过程
作品效果图
#include <Arduino.h>
#include <U8glib.h>

#include <Microduino_Motor.h>
int var_speed;
U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NONE);

Motor MotorRight(MOTOR1_PINA, MOTOR1_PINB);
Motor MotorLeft(MOTOR0_PINA, MOTOR0_PINB);
uint8_t playIndex = 0;
void playoff(uint8_t pin)
{
    playIndex = 100;
    noTone(pin);
}
#define SONG_SUM 11
uint16_t toneList[] = { 262, 294, 330, 349, 392, 440, 494, 523, 587, 659, 698, 784, 880, 988, 1046, 1175, 1318, 1397, 1568, 1760, 1967 };
uint8_t music_1[] = { 12, 10, 12, 10, 12, 10, 9, 10, 12, 12, 12, 10, 13, 12, 10, 12, 10, 9, 8, 9, 10, 12, 10, 9, 8, 9, 10, 0 };
uint8_t rhythm_1[] = { 4, 2, 4, 2, 2, 2, 2, 2, 8, 2, 4, 2, 4, 4, 2, 2, 2, 2, 4, 4, 4, 4, 2, 2, 2, 2, 8 };
uint8_t music_2[] = { 8, 9, 10, 8, 8, 9, 10, 8, 10, 11, 12, 10, 11, 12, 0 };
uint8_t rhythm_2[] = { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 8, 4, 4, 8 };
uint8_t music_3[] = { 5, 8, 8, 10, 13, 10, 12, 12, 13, 12, 10, 11, 10, 9, 6, 9, 9, 11, 14, 14, 13, 12, 11, 11, 10, 6, 7, 8, 9 , 0 };
uint8_t rhythm_3[] = { 2, 1, 2, 1, 2, 1, 4, 2, 1, 2, 1, 2, 1, 4, 2, 1, 2, 1, 2, 1, 2, 1, 4, 2, 1, 2, 4, 2, 8 };
uint8_t music_4[] = { 5, 5, 6, 5, 8, 7, 5, 5, 6, 5, 9, 8, 5, 5, 12, 10, 8, 7, 6, 11, 11, 10, 8, 9, 8, 0 };
uint8_t rhythm_4[] = { 2, 2, 4, 4, 4, 8, 2, 2, 4, 4, 4, 8, 2, 2, 4, 4, 4, 4, 4, 2, 2, 4, 4, 4, 8 };
uint8_t music_5[] = { 12, 13, 12, 13, 12, 13, 12, 12, 15, 14, 13, 12, 13, 12, 12, 12, 10, 10, 12, 12, 10, 9, 11, 10, 9, 8, 9, 8, 0  };
uint8_t rhythm_5[] = { 2, 2, 2, 2, 2, 2, 4, 2, 2, 2, 2, 2, 2, 4, 2, 2, 2, 2, 2, 2, 4, 2, 2, 2, 2, 2, 2, 4 };
uint8_t music_6[] = { 8, 8, 10, 8, 8, 10, 22, 13, 13, 13, 12, 13, 12, 8, 10, 22, 15, 13, 13, 12, 13, 12, 8, 9, 22, 14, 14, 12, 10, 12, 0  };
uint8_t rhythm_6[] = { 4, 4, 8, 2, 4, 4, 4, 4, 4, 2, 2, 4, 2, 4, 4, 4, 2, 2, 2, 2, 8, 2, 4, 4, 4, 4, 2, 2, 4, 16 };
uint8_t music_7[] = { 6, 8, 9, 10, 12, 10, 8, 9, 6, 22, 8, 9, 10, 12, 12, 13, 9, 10, 22, 10, 12, 13, 12, 13, 15, 14, 13, 12, 13, 10, 8, 9, 10, 12, 8, 6, 8, 9, 10, 13, 12 , 0 };
uint8_t rhythm_7[] = { 2, 2, 2, 4, 2, 2, 2, 4, 8, 2, 2, 2, 2, 4, 2, 4, 4, 8, 4, 2, 2, 8, 4, 2, 2, 1, 1, 2, 2, 4, 2, 2, 4, 2, 4, 4, 2, 2, 2, 2, 18 };
uint8_t music_8[] = { 10, 8, 9, 6, 10, 9, 8, 9, 6, 10, 8, 9, 9, 12, 10, 7, 8, 8, 7, 6, 7, 8, 9, 5, 13, 12, 10, 10, 9, 8, 9, 10, 9, 10, 9, 12, 12, 12, 12, 12, 12, 0  };
uint8_t rhythm_8[] = { 4, 4, 4, 4, 2, 2, 2, 2, 8, 4, 4, 4, 4, 2, 2, 4, 4, 2, 2, 4, 2, 2, 4, 4, 2, 2, 4, 4, 2, 4, 2, 2, 2, 2, 2, 4, 2, 2, 2, 2, 4 };
uint8_t music_9[] = { 10, 12, 15, 13, 12, 10, 12, 13, 15, 12, 15, 17, 16, 15, 16, 15, 13, 15, 12 , 0 };
uint8_t rhythm_9[] = { 2, 2, 2, 2, 8, 2, 2, 2, 2, 8, 4, 2, 4, 4, 2, 2, 2, 2, 8 };
uint8_t music_10[] = { 10, 10, 10, 8, 5, 5, 22, 10, 10, 10, 8, 10, 22, 12, 12, 10, 8, 5, 5, 5, 6, 7, 8, 10, 9, 0  };
uint8_t rhythm_10[] = { 2, 2, 2, 2, 4, 2, 2, 2, 2, 2, 2, 4, 4, 2, 2, 2, 2, 2, 2, 4, 2, 2, 2, 2, 4 };
uint8_t music_11[] = {8, 9, 10, 8, 8, 9, 10, 8, 10, 11, 12, 10, 11, 12, 0};
uint8_t rhythm_11[] = {2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 4, 2, 2,  4};

const uint8_t * Pmusic[SONG_SUM] =
{
    music_1, music_2, music_3, music_4, music_5, music_6, music_7, music_8, music_9, music_10, music_11
}
;
const uint8_t * Prhythm[SONG_SUM] =
{
    rhythm_1, rhythm_2, rhythm_3, rhythm_4, rhythm_5, rhythm_6, rhythm_7, rhythm_8, rhythm_9, rhythm_10, rhythm_11
}
;
uint32_t playTimer = 0;
int8_t songNumC = -1;
uint8_t songIndex;
uint8_t playSound(uint8_t pin, uint8_t songNum)
{
    songIndex = songNum;
    if (songNum > SONG_SUM - 1)
    {
        noTone(pin);
        return;
    }
    if (playIndex == 100 || songNumC != songNum)
    {
        playIndex = 0;
        songNumC = songNum;
    }
    if (millis() > playTimer && (*(Pmusic[songNum] + playIndex / 2)))
    {
        if (playIndex % 2 == 0)
        {
            if (*(Pmusic[songNum] + playIndex / 2) != 22)
            tone(pin, toneList[*(Pmusic[songNum] + playIndex / 2) - 1]);
            else
            noTone(pin);
            playTimer = millis() + *(Prhythm[songNum] + playIndex / 2) * 75;
        }
        else
        {
            noTone(pin);
            playTimer = millis() + 40;
        }
        playIndex++;
    }
}
void playingRest()
{
    if (playIndex != 100)
    {
        playIndex = 0;
    }
}
boolean playingStop()
{
    if (*(Pmusic[songIndex] + playIndex / 2))
    {
        return false;
    }
    else
    {
        return true;
    }
}


void setup()
{
    MotorRight.begin();
    MotorLeft.begin();
    pinMode(2, OUTPUT);
    pinMode(4, OUTPUT);
    pinMode(6, OUTPUT);
    pinMode(8, OUTPUT);
    var_speed=50;

}

void loop()
{
    u8g.setFont(u8g_font_9x15);
    u8g.firstPage();
    do
    {

        u8g.setPrintPos(50, 10);
        u8g.print((analogRead(A0)));


        u8g.setPrintPos(80, 50);
        u8g.print((analogRead(A2)));


        u8g.setPrintPos(10, 50);
        u8g.print((analogRead(A6)));


    }
    while (u8g.nextPage());

    if(((((analogRead(A0)) < 400)) && (((300 < (analogRead(A2)))) && ((400 < (analogRead(A6)))))))
    {
        MotorRight.setSpeed(var_speed);
        MotorLeft.setSpeed(0-(var_speed));
        digitalWrite(2,1);
        digitalWrite(4,1);
        digitalWrite(6,1);
        digitalWrite(8,1);
        delay(2*1000);
        digitalWrite(2,0);
        digitalWrite(4,0);
        if(((random(1,10)) > 5))
        {
            MotorRight.setSpeed(0-(var_speed));
            MotorLeft.setSpeed(0-(var_speed));

        }
        else
        {
            MotorRight.setSpeed(var_speed);
            MotorLeft.setSpeed(var_speed);

        }
        delay(2*1000);

    }
    else
    {
        if((((400 < (analogRead(A0)))) && (((400 < (analogRead(A2)))) && (((analogRead(A6)) < 400)))))
        {
            MotorRight.setSpeed(0-(var_speed));
            MotorLeft.setSpeed(0-(var_speed));
            digitalWrite(6,1);
            digitalWrite(8,1);

        }
        else
        {
            if((((400 < (analogRead(A0)))) && (((400 < (analogRead(A6)))) && (((analogRead(A2)) < 400)))))
            {
                MotorRight.setSpeed(var_speed);
                MotorLeft.setSpeed(var_speed);

            }
            else
            {
                MotorLeft.setSpeed(var_speed);
                MotorRight.setSpeed(0-(var_speed));
                if (!playingStop())
                {
                    playSound(10, 8-1);
                }
                else
                {
                    playingRest();
                }

            }

        }

    }

}
#include <Arduino.h>
#include <Microduino_ColorLED.h>

#include <Microduino_Matrix.h>
int var_variable;
ColorLED strip_8 = ColorLED(16, 8);

uint8_t Addr[MatrixPix_X][MatrixPix_Y] =
{
    {
        64
    }
}
;
Matrix display = Matrix(Addr, TYPE_COLOR);

uint8_t rgbArray_64_839259120_2[8][8][3]=
{
    {
        {184,184,184},{184,184,184},{184,184,184},{184,184,184},{184,184,184},{184,184,184},{184,184,184},{184,184,184}},{{184,184,184},{184,184,184},{255,0,0},{255,0,0},{255,0,0},{255,0,0},{184,184,184},{184,184,184}},{{184,184,184},{184,184,184},{184,184,184},{184,184,184},{184,184,184},{255,0,0},{184,184,184},{184,184,184}},{{184,184,184},{184,184,184},{255,0,0},{255,0,0},{255,0,0},{255,0,0},{184,184,184},{184,184,184}},{{184,184,184},{184,184,184},{255,0,0},{184,184,184},{184,184,184},{184,184,184},{184,184,184},{184,184,184}},{{184,184,184},{184,184,184},{255,0,0},{255,0,0},{255,0,0},{255,0,0},{184,184,184},{184,184,184}},{{184,184,184},{184,184,184},{184,184,184},{184,184,184},{184,184,184},{184,184,184},{184,184,184},{184,184,184}},{{184,184,184},{184,184,184},{184,184,184},{184,184,184},{184,184,184},{184,184,184},{184,184,184},{184,184,184}
    }

}
;

uint8_t rgbArray_64_723650032_3[8][8][3]=
{
    {
        {184,184,184},{184,184,184},{184,184,184},{184,184,184},{184,184,184},{184,184,184},{184,184,184},{184,184,184}},{{184,184,184},{184,184,184},{128,255,0},{128,255,0},{128,255,0},{128,255,0},{184,184,184},{184,184,184}},{{184,184,184},{184,184,184},{184,184,184},{184,184,184},{184,184,184},{128,255,0},{184,184,184},{184,184,184}},{{184,184,184},{184,184,184},{128,255,0},{128,255,0},{128,255,0},{128,255,0},{184,184,184},{184,184,184}},{{184,184,184},{184,184,184},{184,184,184},{184,184,184},{184,184,184},{128,255,0},{184,184,184},{184,184,184}},{{184,184,184},{184,184,184},{128,255,0},{128,255,0},{128,255,0},{128,255,0},{184,184,184},{184,184,184}},{{184,184,184},{184,184,184},{184,184,184},{184,184,184},{184,184,184},{184,184,184},{184,184,184},{184,184,184}},{{184,184,184},{184,184,184},{184,184,184},{184,184,184},{184,184,184},{184,184,184},{184,184,184},{184,184,184}
    }

}
;

uint8_t rgbArray_64_730079714_4[8][8][3]=
{
    {
        {184,184,184},{184,184,184},{184,184,184},{184,184,184},{184,184,184},{184,184,184},{184,184,184},{184,184,184}},{{184,184,184},{184,184,184},{136,0,255},{136,0,255},{136,0,255},{136,0,255},{184,184,184},{184,184,184}},{{184,184,184},{184,184,184},{184,184,184},{184,184,184},{184,184,184},{136,0,255},{184,184,184},{184,184,184}},{{184,184,184},{184,184,184},{136,0,255},{136,0,255},{136,0,255},{136,0,255},{184,184,184},{184,184,184}},{{184,184,184},{184,184,184},{184,184,184},{184,184,184},{184,184,184},{136,0,255},{184,184,184},{184,184,184}},{{184,184,184},{184,184,184},{136,0,255},{136,0,255},{136,0,255},{136,0,255},{184,184,184},{184,184,184}},{{184,184,184},{184,184,184},{184,184,184},{184,184,184},{184,184,184},{184,184,184},{184,184,184},{184,184,184}},{{184,184,184},{184,184,184},{184,184,184},{184,184,184},{184,184,184},{184,184,184},{184,184,184},{184,184,184}
    }

}
;

uint8_t rgbArray_64_606211606_5[8][8][3]=
{
    {
        {184,184,184},{184,184,184},{184,184,184},{184,184,184},{184,184,184},{184,184,184},{184,184,184},{184,184,184}},{{184,184,184},{184,184,184},{0,255,149},{0,255,149},{0,255,149},{0,255,149},{184,184,184},{184,184,184}},{{184,184,184},{184,184,184},{184,184,184},{184,184,184},{184,184,184},{0,255,149},{184,184,184},{184,184,184}},{{184,184,184},{184,184,184},{0,255,149},{0,255,149},{0,255,149},{0,255,149},{184,184,184},{184,184,184}},{{184,184,184},{184,184,184},{184,184,184},{184,184,184},{184,184,184},{0,255,149},{184,184,184},{184,184,184}},{{184,184,184},{184,184,184},{0,255,149},{0,255,149},{0,255,149},{0,255,149},{184,184,184},{184,184,184}},{{184,184,184},{184,184,184},{184,184,184},{184,184,184},{184,184,184},{184,184,184},{184,184,184},{184,184,184}},{{184,184,184},{184,184,184},{184,184,184},{184,184,184},{184,184,184},{184,184,184},{184,184,184},{184,184,184}
    }

}
;


void setup()
{
    strip_8.begin();

    Wire.begin();


}

void loop()
{
    while(!((400 > (analogRead(A0)))));
    var_variable=60;
    for(int i=0;i<30;i++)
    {
        strip_8.setPixelColor(0,((var_variable)-60)*4);

        strip_8.show();
        strip_8.setPixelColor(1,((var_variable)-60)*4);

        strip_8.show();
        var_variable+=(1);
    }
    for(int i=0;i<30;i++)
    {
        strip_8.setPixelColor(0,((var_variable)-60)*4);

        strip_8.show();
        strip_8.setPixelColor(1,((var_variable)-60)*4);

        strip_8.show();
        var_variable+=(-1);
        delay(0.05*1000);
    }
    delay(1*1000);
    for (int y = 0; y < 8; y++)
    {
        for (int x = 0; x <8; x++)
        {
            display.setLedColor(x, y, rgbArray_64_839259120_2[y][x][0], rgbArray_64_839259120_2[y][x][1],rgbArray_64_839259120_2[y][x][2]);
        }
    }
    delay(1*1000);
    for (int y = 0; y < 8; y++)
    {
        for (int x = 0; x <8; x++)
        {
            display.setLedColor(x, y, rgbArray_64_723650032_3[y][x][0], rgbArray_64_723650032_3[y][x][1],rgbArray_64_723650032_3[y][x][2]);
        }
    }
    delay(1*1000);
    for (int y = 0; y < 8; y++)
    {
        for (int x = 0; x <8; x++)
        {
            display.setLedColor(x, y, rgbArray_64_730079714_4[y][x][0], rgbArray_64_730079714_4[y][x][1],rgbArray_64_730079714_4[y][x][2]);
        }
    }
    delay(1*1000);
    for (int y = 0; y < 8; y++)
    {
        for (int x = 0; x <8; x++)
        {
            display.setLedColor(x, y, rgbArray_64_606211606_5[y][x][0], rgbArray_64_606211606_5[y][x][1],rgbArray_64_606211606_5[y][x][2]);
        }
    }

}


代码展示
暂无数据!
附件下载
  • 资料展示
  • 5组_万欣豪_智能避障小车.zip
0
大牛,别默默的看了,快登录帮我点评一下吧!

立即注册