DayDreaming 发表于 2018-9-9 12:44:51

第三轮挑战:胡来的色盲救星

本帖最后由 DayDreaming 于 2018-9-9 12:44 编辑

【生活场景】
我们办公室有个红绿色盲,在我们看来非常清楚的红色和绿色,
他就分辨不清。

http://img2.dzwww.com:8888/tupian/20170410/201704101835846681b8oj0jya_640.jpg
想要看清楚这种图,对他来说简直比考北大还难。
他一般会请我们帮忙告诉他这是什么颜色。
BUT!没人可求助的时候怎么办?
出于人道主义关怀,我决定做个色盲救星~

【小调研】
早在2017年,我就带着学生对色盲辅助设备做了调查研究。
1. 色盲的世界

2. 色盲眼镜

3. 缺陷和不足

4. 总之,色盲的需求是:能够知道自己看到的是什么颜色。

【我的设想】
设计这样一款便携式装置:
1. 对准有颜色的东西,哪里分辨不出就点哪里;(有点吸颜色的意思)2. 宏观上给出颜色名称。(红橙黄绿青蓝紫……)
      ///// 英文小科普 /////(microbit端用这些首字母代表各个颜色名称) 【作品亮点】1. 实现arduino和microbit互相通信:lol2. 实现根据RGB值来判断颜色名称的粗糙算法:$
【制作过程】1. 材料清单micro:bit —— x1micro:mate —— x1obloq模块 —— x2arduino uno —— x1颜色传感器 —— x1 (敲可耐的传感器:victory:)按键 —— x1220欧电阻 —— x1杜邦线 —— 若干
2. arduino端硬件联接用到了颜色传感器,obloq模块,按键,220欧电阻
软件编程
拾取RGB值—>转换成宏观颜色值—>上传到EasyIoT平台
    //////算法小科普//////


#include "Arduino.h"
#include "SoftwareSerial.h"
#include "Obloq.h"
#include <Wire.h>
#include "DFRobot_TCS34725.h"
#define commonAnode true
/*颜色传感器*/
byte gammatable;// our RGB -> eye-recognized gamma color
DFRobot_TCS34725 tcs = DFRobot_TCS34725(TCS34725_INTEGRATIONTIME_50MS, TCS34725_GAIN_4X);
/*Obloq物联网*/
SoftwareSerial softSerial(10,11);
//生成OBLOQ对象,参数:串口指针,wifiSsid,WifiPwd,iotId,iotPwd
//Generate OBLOQ object, parameters: serial pointer, wifiSsid, WifiPwd, iotId, iotPwd
Obloq olq(&softSerial,"iPhone","qwertyuiop","Hy-fUhuuXX","B1GGLhdO7Q");
const String devTopic = "HJRQpd_XQ";
static unsigned long currentTime = 0;
unsigned long messageCount = 1;
/*按键*/
const int buttonPin = 2;
int buttonState = 0;

void setup()
{
    /*obloq物联网*/
    softSerial.begin(9600);
   
    /*颜色传感器*/
    Serial.begin(115200);
    Serial.println("Color View Test!");

    if (tcs.begin()) {
      Serial.println("Found sensor");
    } else {
      Serial.println("No TCS34725 found ... check your connections");
      while (1); // halt!
    }
   
    // thanks PhilB for this gamma table!
    // it helps convert RGB colors to what humans see
    for (int i=0; i<256; i++) {
      float x = i;
      x /= 255;
      x = pow(x, 2.5);
      x *= 255;
      
      if (commonAnode) {
      gammatable = 255 - x;
      } else {
      gammatable = x;      
      }
      //Serial.println(gammatable);
    }

    /*按键*/
    pinMode(buttonPin,INPUT);
}

void loop()
{
    /*按键*/
    buttonState = digitalRead(buttonPin);
    if(buttonState == HIGH){
      getColor();//颜色识别函数
    }
   
    /*obloq物联网
    olq.update();
    if(millis() - currentTime > 10000)
    {
      currentTime =millis();
      //向设备发送消息,设备Topic,消息内容:从1开始累加的计数
      //Publish message to device (Topic), message contents: accumulated numbers counting from 1.
      olq.publish(devTopic, "red");
    }*/
}
void getColor(){
    uint16_t clear, red, green, blue;
    tcs.getRGBC(&red, &green, &blue, &clear);
    tcs.lock();// turn off LED
    Serial.print("C:\t"); Serial.print(clear);
    Serial.print("\tR:\t"); Serial.print(red);
    Serial.print("\tG:\t"); Serial.print(green);
    Serial.print("\tB:\t"); Serial.print(blue);
    Serial.println("\t");
   
    // Figure out some basic hex code for visualization
    uint32_t sum = clear;
    float r, g, b;
    r = red; r /= sum;
    g = green; g /= sum;
    b = blue; b /= sum;
    r *= 256; g *= 256; b *= 256;
    Serial.print("\t");
    Serial.print((int)r, HEX); Serial.print((int)g, HEX); Serial.print((int)b, HEX);
    Serial.println();

    String msg;
    /*由RGB->颜色*/
    if(r>g*1.2 && r>b*1.2) msg = "R";//红色
    else if(g>r*1.2 && g>b*1.2) msg = "G";//绿色
    else if(b>r*1.2 && b>g*1.2) msg = "B";//蓝色
    else if(r>b*1.2 && g>b*1.2 && fabs(r-g)<0.5*r && fabs(r-g)<0.5*g) msg = "Y";//黄色
    else if(r>g*1.2 && b>g*1.2 && fabs(r-b)<0.5*r && fabs(r-b)<0.5*b) msg = "M";//梅红
    else if(g>r*1.2 && b>r*1.2 && fabs(g-b)<0.5*g && fabs(g-b)<0.5*b) msg = "C";//青色
    else msg = "NA";//暂时无法判断的颜色
   
    /*obloq物联网*/
    olq.update();
    olq.publish(devTopic, msg);
}



3. microbit端硬件联接
软件编程这个程序可以说是相当简单了【捂脸】
【视频王道】https://v.qq.com/x/page/p0781h1szkn.html
【自我检讨】1. microbit做个外壳可以像摆台一样放在桌上,随时查看屏幕里显示的颜色名称。2. arduino做个包装把林乱的走线都埋起来,把颜色传感器包装一下,做成马克笔的样子。(毕竟这个萌萌哒的传感器就指甲盖丁点儿大)3. 优化算法识别颜色更准确,范围更广如:橙色、紫色等4. 增加语音播报功能
THE END :)





朴实的爱 发表于 2018-9-9 22:59:53

这个想法很赞啊。学习了。{:5_148:}

DayDreaming 发表于 2018-9-10 14:20:06

朴实的爱 发表于 2018-9-9 22:59
这个想法很赞啊。学习了。

多谢肯定哈~~~
可惜实现得有点粗糙
页: [1]
查看完整版本: 第三轮挑战:胡来的色盲救星