2022年8月28日日曜日

LearningKit 2022 for M5Stack Gray Controll DCmotor wiz DRV8830


 


//Learning Kit 2022 for M5Stack

//M5Stack_Gray_drv8830_dcmotor 

//Thanks to https://spiceman.jp/arduino-drv8830-program/


#include <M5Stack.h>

#include <Wire.h>

#define DRV8830_ADDR 0x64

#define CONTROL 0x00


void OpenScreen()

{

  M5.Lcd.setCursor(0,0);

  M5.Lcd.setTextColor(WHITE);

  M5.Lcd.setTextSize(2);

  M5.Lcd.print("Welcome to M5Stack Gray");

  M5.Lcd.setCursor(0,20);

  M5.Lcd.print("Coded by Kim Grossa");

  M5.Lcd.setCursor(0,40);

  M5.Lcd.print("Run DCmotor wiz DRV8830");

  

  M5.Lcd.setCursor(0,70);

  M5.Lcd.setTextColor(BLUE);

  M5.Lcd.setTextSize(3);

  M5.Lcd.print("ButtonA Reverse");

  M5.Lcd.setCursor(0,100);

  M5.Lcd.print("ButtonB Stop");

  M5.Lcd.setCursor(0,130);

  M5.Lcd.print("ButtonC Forward");

}


void setup() 

{

  M5.begin();

  M5.Power.begin();

  M5.Lcd.setBrightness(200);


  Wire.begin();

}


void loop() 

{

  boolean aBtn = M5.BtnA.wasPressed();

  boolean bBtn = M5.BtnB.wasPressed();

  boolean cBtn = M5.BtnC.wasPressed();

   

  OpenScreen(); 

   

  if(aBtn)

  { 

    //M5.Lcd.setCursor(0,180);

    //M5.Lcd.setTextColor(GREEN,BLACK);

    //M5.Lcd.setTextSize(3);

    //M5.Lcd.print("Reverse........");

    

    Wire.beginTransmission(DRV8830_ADDR);

    Wire.write(CONTROL);

    Wire.write(0x26<<2|0x02);  //Output 3.05V

    Wire.endTransmission();


    M5.Lcd.setCursor(0,180);

    M5.Lcd.setTextColor(GREEN,BLACK);

    M5.Lcd.setTextSize(3);

    M5.Lcd.print("Press any key");

  }


  if(bBtn)

  {

    //M5.Lcd.setCursor(0,180);

    //M5.Lcd.setTextColor(GREEN,BLACK);

    //M5.Lcd.setTextSize(3);

    //M5.Lcd.print("Stop........"); 


    Wire.beginTransmission(DRV8830_ADDR);

    Wire.write(CONTROL);

    Wire.write(0x00<<2|0x03);

    Wire.endTransmission();

  

    M5.Lcd.setCursor(0,180);

    M5.Lcd.setTextColor(GREEN,BLACK);

    M5.Lcd.setTextSize(3);

    M5.Lcd.print("Press any key");           

  }


  if(cBtn)

  { 

    //M5.Lcd.setCursor(0,180);

    //M5.Lcd.setTextColor(GREEN,BLACK);

    //M5.Lcd.setTextSize(3);

    //M5.Lcd.print("Forward......."); 

    

    Wire.beginTransmission(DRV8830_ADDR);

    Wire.write(CONTROL);

    Wire.write(0x26<<2|0x01);  //Output 3.05V

    Wire.endTransmission();

    

    M5.Lcd.setCursor(0,180);

    M5.Lcd.setTextColor(GREEN,BLACK);

    M5.Lcd.setTextSize(3);

    M5.Lcd.print("Press any key");   

  }


  M5.update();

}

0 件のコメント:

コメントを投稿