12
返回列表 发新帖
楼主: pythonworld

[原创] 【LPC824lite】+倾角测量仪

[复制链接]
  • TA的每日心情
    郁闷
    2018-2-7 18:18
  • 签到天数: 5 天

    连续签到: 1 天

    [LV.2]偶尔看看I

    13

    主题

    126

    帖子

    1

    金牌会员

    Rank: 6Rank: 6

    积分
    1628
    最后登录
    2021-7-13
     楼主| 发表于 2016-11-23 22:12:05 | 显示全部楼层
    本帖最后由 pythonworld 于 2016-11-25 13:44 编辑

    程序更新,串口输出改为3个角度输出, oled输出显示不变.
    #include "mbed.h"
    #include "Adafruit_SSD1306.h"
    #include <math.h>       /* atan2 */

    #define PI 3.14159265

    #define DO P0_24    //CLK
    #define DI P0_26    // MOSI
    #define CS P0_10
    #define DC P0_11
    #define RST P0_17

    class SPIPreInit : public SPI
    {
    public:
        SPIPreInit(PinName mosi, PinName miso, PinName clk) : SPI(mosi,miso,clk) {
            format(8,3);
            frequency(2000000);
        };
    };

    SPIPreInit mySpi(DI,NC,DO);
    Adafruit_SSD1306_Spi oled(mySpi,DC,RST,CS,64,128);

    DigitalOut myled1(P0_13);
    DigitalOut myled2(P0_16);
    DigitalOut myled3(P0_17);

    DigitalIn myinput1(P0_6);
    DigitalIn myinput2(P0_14);
    DigitalIn myinput3(P0_22);

    Serial uart(P0_4, P0_0);

    AnalogIn myadc1(A0);
    AnalogIn myadc2(A1);
    AnalogIn myadc3(A3);

    int main()
    {

        double x, y, z, result;
        myinput1.mode(PullNone);
        myinput2.mode(PullNone);
        myinput3.mode(PullNone);

        oled.clearDisplay();
        oled.setTextSize(2);
        oled.setTextCursor(0,0);

        while(1) {

            uart.printf("X: %2.3f V\r\n" ,myadc1.read()*3.3);
            uart.printf("Y: %2.3f V\r\n" ,myadc2.read()*3.3);
            uart.printf("Z: %2.3f V\r\n" ,myadc3.read()*3.3);
            x = (myadc1.read()*3.3-1.646)*3048.78;
            y = (myadc2.read()*3.3-1.642)*3025.72;
            z = (myadc3.read()*3.3-1.672)*3067.48;
            
            result = atan2(x,sqrt(z*z+y*y))*180/PI;
            uart.printf("Alpha: %2.3f degrees\r\n" ,result);
            
            result = atan2(y,sqrt(z*z+x*x))*180/PI;
            uart.printf("Beta: %2.3f degrees\r\n" ,result);
            
            result = atan2(z,sqrt(x*x+y*y))*180/PI;
            uart.printf("Gamma: %2.3f degrees\r\n" ,result);
            
            result = atan2 (x,z) * 180 / PI;
            uart.printf ("The arc tangent for (x=%f, y=%f) is %.4f degrees\r\n", x, z, result );
            oled.printf (" %.2f D\r\n",result);
            oled.printf ("Y: %.0f mg\r\n",y);

            myled1 = 1;
            myled2 = 0;
            myled3 = 1;

            oled.display();

            wait(1.5);
            oled.setTextCursor(0,0);
            oled.clearDisplay();
        }
    }
    该会员没有填写今日想说内容.
    回复 支持 反对

    使用道具 举报

  • TA的每日心情
    开心
    2018-12-8 10:21
  • 签到天数: 743 天

    连续签到: 1 天

    [LV.9]以坛为家II

    0

    主题

    1650

    帖子

    0

    金牌会员

    Rank: 6Rank: 6

    积分
    19069
    最后登录
    2021-5-6
    发表于 2016-11-24 07:52:56 | 显示全部楼层
    图片来了,纯友情支持 帮顶
    我又来签到了.
    回复 支持 反对

    使用道具 举报

  • TA的每日心情
    郁闷
    2018-2-7 18:18
  • 签到天数: 5 天

    连续签到: 1 天

    [LV.2]偶尔看看I

    13

    主题

    126

    帖子

    1

    金牌会员

    Rank: 6Rank: 6

    积分
    1628
    最后登录
    2021-7-13
     楼主| 发表于 2016-11-24 19:38:44 | 显示全部楼层
    本帖最后由 pythonworld 于 2016-11-24 19:39 编辑
    zbber 发表于 2016-11-24 07:52
    图片来了,纯友情支持 帮顶

    谢谢!多提宝贵意见。
    该会员没有填写今日想说内容.
    回复 支持 反对

    使用道具 举报

    您需要登录后才可以回帖 注册/登录

    本版积分规则

    关闭

    站长推荐上一条 /3 下一条

    Archiver|手机版|小黑屋|恩智浦技术社区

    GMT+8, 2025-8-21 15:03 , Processed in 0.196149 second(s), 20 queries , MemCache On.

    Powered by Discuz! X3.4

    Copyright © 2001-2024, Tencent Cloud.

    快速回复 返回顶部 返回列表