博客來網路書店查詢

書名

博客來網路書店查詢

星期日, 5月 29, 2016

組裝的第二個問題-電池供電給Arduino板子




Arjin Chen 老師說:
 本例由電池供電給Arduino板子有2種方式
1. 使用圖一的DC快速接頭(公頭), 接至Arduino板子的DC母插座, 正極是接至L298N的12V-GND-5V插座中的5V
2. 直接由L298N 5V拉一條線(杜邦公公線即可)接至Arduino板子的VIN供電
1是之前的接法, 2是簡化後的接法, 都可以
--
L298N的GND一條是接到電池負極, 一條是接到Arduino板的GND
--
因掃地機有多個馬達, 故電池採用4節+2節(原2馬達輪子用的話, 4節就夠了), 所以請將4+2電池盒串聯(4節的黑接到2節的紅)即可
--
快速接頭使用較彈性, 一個可用在掃地機, 另一個可搭配9V電池扣, 使用9V電池供電給離線的Arduino板使用(例機械手臂、LED/LCD)

另外一個配線的補充

星期五, 5月 27, 2016

C++與SQLite--資料列表

void getTableData()
{
    sqlite3_stmt *statement;
    char *query = "select * from student";
    if ( sqlite3_prepare(dbfile, query, -1, &statement, 0 ) == SQLITE_OK )
    {
        int ctotal = sqlite3_column_count(statement);
        int res = 0;
        while ( 1 )
        {
            res = sqlite3_step(statement);
            if ( res == SQLITE_ROW )
            {
                for ( int i = 0; i < ctotal; i++ )
                {
                    string s = (char*)sqlite3_column_text(statement, i);
                    cout << s << " " ;
                }
                cout << endl;
            }
            if ( res == SQLITE_DONE )
            {
                cout << "done " << endl;
                break;
            }
        }
    }
}

C++與SQLite--刪除資料

int deleteRow()
{
    int rollno;
    cout << " 輸入學號 :" ;
    cin >> rollno ;
    if(cin.fail( ))
    {
      cin.clear( );
      cout<<"學號格式錯了";
      return 0;
    }
    std::stringstream strm;
    strm << "delete from student " << " where roll=" << rollno ;
    string s = strm.str();
    char *str = &s[0];
    //cout << str << endl;
    sqlite3_stmt *statement;
    int result;
    char *query = str;
    {
        if(sqlite3_prepare(dbfile,query,-1,&statement,0)==SQLITE_OK)
        {
            int res=sqlite3_step(statement);
            result=res;
            sqlite3_finalize(statement);
        }
        return result;
    }
    return 0;
}

C++與SQLite--更新資料

int updateRow()
{
    int rollno;
    float gpa;
    cout << " 輸入學號 :" ;
    cin >> rollno ;
    if(cin.fail( ))
    {
      cin.clear( );
      cout<<"學號格式錯了";
      return 0;
    }
    cout << " 輸入新的平均成績 : " ;
    cin >> gpa;
    if(cin.fail( ))
    {
      cin.clear( );
      cout<<"成績格式錯了";
      return 0;
    }
    std::stringstream strm;
    strm << "update student set cgpa=" << gpa << " where roll=" << rollno ;
    string s = strm.str();
    char *str = &s[0];
    //cout << str << endl;
    sqlite3_stmt *statement;
    int result;
    //char *query="update student set cgpa=3.66 where roll=11";
    char *query = str;
    {
        if(sqlite3_prepare(dbfile,query,-1,&statement,0)==SQLITE_OK)
        {
            int res=sqlite3_step(statement);
            result=res;
            sqlite3_finalize(statement);
        }
        return result;
    }
    return 0;
}

C++與SQLite--新增資料

student getStudent()
{
    student stud;
    int id;
    string name;
    float gpa;
    cout << " 輸入學號 :" ;
    cin >> id;
    if(cin.fail( ))
    {
      cin.clear( );
      cout<<"學號格式錯了";
    }
    cout << " 輸入姓名 : " ;
    cin >> name;
    cout << " 輸入平均成績 : " ;
    cin >> gpa;
    if(cin.fail( ))
    {
      cin.clear( );
      cout<<"成績格式錯了";
    }
    stud.setid(id);
    stud.setName(name);
    stud.setcgpa(gpa);
    return stud;
}
int addDataRow()
{
    student stud = getStudent();
    //cout << stud.getName() << endl;
    std::stringstream strm;
    strm << "insert into student(roll,name,cgpa) values(" << stud.getid() << ",'" << stud.getName() << "'," << stud.getcgpa() << ")";
    string s = strm.str();
    char *str = &s[0];
    //cout << str << endl;
    sqlite3_stmt *statement;
    int result;
    //char *query="insert into student(roll,name,cgpa)values(4,'uuu',6.6)";
    char *query = str;
    {
        if(sqlite3_prepare(dbfile,query,-1,&statement,0)==SQLITE_OK)
        {
            int res=sqlite3_step(statement);
            result=res;
            sqlite3_finalize(statement);
        }
        return result;
    }
    return 0;
}

C++與SQLite--引用項目

#include
#include
#include
#include
#include
using namespace std;
#include "sqlite3.h"
#define DB "sea.s3db"
bool isOpenDB = false;
sqlite3 *dbfile;
bool ConnectDB ( );
void DisonnectDB ( );

組裝時的問題-馬達與感測器




Arjin Chen老師回應:
那一條是GND, 接在任一GND(接地)即可, 以你目前線色看來
綠-->5V
藍-->A0(左)/2(中)/4(右)
紫-->A1(左)/3(中)/5(右)
灰-->GND

Litamei Chen 老師回應:
您好
黑色線是接地GND

吳慧琳老師回應:

A.二個馬達二條各接IDE板GND+5V

B.感測三組四條接法一樣如下:
最左邊接5V
最右邊接GND
其他中間二個又分如下:
左感應接A0,1
中感應接A2,3
右感應接A4,5




我再補一張圖片說明感測器

星期六, 5月 21, 2016

C Sharp 上課六次的主題

理論上是有點多,所以希望上課的學員先上過C/C++初進階之後再上我的課程,比較能了解我在說甚麼。
因為書本太厚加上時間太短,所以我自己有安排主題,六天課程我的安排進度如下
 第一天 數值計算、資料輸入與例外處理、條件分析
第二天 迴圈、陣列、引用VB的inputbox進行練習
第三天 亂數、ArrayList、圖片控制項的使用
第四天 兩個按鈕使用同一個函數、大量圖片使用、三個骰子遊戲
第五天 textBox能力的繼承、自己建立DLL檔案、使用者控制項轉為dll、影音播放
第六天 快顯選單、多表單、點唱機

當然如果大家之後有其他想法可以跟我說,我們上課主題可以變更。

人類繼承觀念內的子類別部分

class son1:public father1
{
public:
      float money;
    son1( )
    {
        money=father1::money*0.6;
        father1::money=father1::money- money;
        cout << "son1 father1 money="<        cout << "son1  money="<    }
};
class son2:public father1
{
public:
      float money;
    son2( )
    {
        cout << "son2 father1 money="<        money=father1::money*0.4;
    }
};
class grandson:public son1
{
public:
    float money;
    grandson( )
    {
        cout << "grandson father1 money="<        money=son1::money*0.6;
        son1::money=son1::money-money;
        cout << "grandson  money="<< money<< endl;
        cout << "grandson son1 money="<< son1::money<< endl;
    }
};

星期五, 5月 20, 2016

關於this

class部分
class Box
{
   public:
      Box(double l=2.0, double b=2.0, double h=2.0)
      {
         cout <<"建立物件" << endl;
         length = l;
         breadth = b;
         height = h;
      }
      double Volume()
      {
         return length * breadth * height;
      }
      int compare(Box box)
      {
         return this->Volume() > box.Volume();
      }
   private:
      double length;     
      double breadth;     
      double height;     
};
 
程式流程
 
   Box Box1(3.3, 1.2, 1.5);    
   Box Box2(8.5, 6.0, 2.0);    

   if(Box1.compare(Box2))
   {
      cout << "Box2 小於 Box1" <<endl;
   }
   else
   {
      cout << "Box2 大於等於 Box1" <<endl;
   }