这些小活动你都参加了吗?快来围观一下吧!>>
电子产品世界 » 论坛首页 » DIY与开源设计 » 开源硬件 » [已完结]公告板兼采集站项目(WiDo板卡测评)

共13条 2/2 1 2 跳转至
工程师
2015-07-13 11:33:15     打赏
11楼

最后是公共板的几张实际效果照片


工程师
2015-07-13 11:44:45     打赏
12楼

公共板WiDo上的源码公布

InfoBoardLite.ino:

#include"LED_Array.h"
/*感谢为“LED_Array”做贡献的:穆诗、Cont、丁Hao 等*/
#include <SPI.h>
#include <Adafruit_CC3000.h>
unsigned int NumOfWord = 0;
#define    DataOfPage    128
#define    NumOfPage    5
unsigned char Data[DataOfPage*NumOfPage];
unsigned long Time;
Adafruit_CC3000 cc3000 = Adafruit_CC3000(10, 7, 5, SPI_CLOCK_DIVIDER);
#define WLAN_SSID       "TP-LINK_7A9FB8"
#define WLAN_PASS       "enteryoupassword"
#define WLAN_SECURITY   WLAN_SEC_WPA2
#define IDLE_TIMEOUT_MS  3000
#define WEBSITE      "helloworld.pw"
#define WEBPAGE      "/wido/display.shtml"
uint32_t ip;
void setup()
{
  TimeCont(0);
  Init_LED_Array();
  Serial.begin(9600);
  Serial.println("LED Arry Ready!");
  Init_WIFI();
  while (NumOfWord == 0)
  {
    Get_Data();
    if(NumOfWord == 0)
    delay(20000);
  }
  Serial.print("Runing!Loader Time: ");
  Serial.print(TimeCont(1) / 1000);
  Serial.println("s");
  TimeCont(0);
}

void loop()
{
  int i;
  int n;
  for (i = 0; i < NumOfWord / 4 + ((NumOfWord % 4>0)?1:0); i++)
  {
    for (n = 80; n > 1; n--)
    {
      Write_LED_Array(0, &Data[i * DataOfPage], L0);
      Write_LED_Array(0, &Data[i * DataOfPage + 64], G1);
    }
  }
  if (TimeCont(1) / 60000 > 4)
  {
    TimeCont(0);
    Get_Data();
    Serial.print("Does!Loader Time: ");
    Serial.print(TimeCont(1));
    Serial.println("ms");
    TimeCont(0);
  }
}

unsigned long TimeCont(char _do)
{
  if (_do != 0)
    return millis() - Time;
  Time = millis();
}

void Init_WIFI(void)
{
  Serial.println(F("Hello, CC3000!"));
  /* Initialise the module */
  Serial.println(F("Initializing..."));
  if (!cc3000.begin())
  {
    Serial.println(F("Couldn't begin()! Check your wiring?"));
    while (1);
  }
  Serial.print(F("Attempting to connect to ")); Serial.print(WLAN_SSID);
  if (!cc3000.connectToAP(WLAN_SSID, WLAN_PASS, WLAN_SECURITY)) {
    Serial.println(F("...Failed!"));
    while (1);
  }
  Serial.println(F("...Connected!"));

  /* Wait for DHCP to complete */
  Serial.print(F("Request DHCP..."));
  while (!cc3000.checkDHCP())
  {
    delay(100); // ToDo: Insert a DHCP timeout!
  }
  Serial.println(F("OK!"));
  while (! displayConnectionDetails()) {
    delay(1000);
  }
  ip = 0;
  Serial.print("ping: ");  Serial.print(WEBSITE); Serial.print(F(" -> "));
  while (ip == 0) {
    if (! cc3000.getHostByName(WEBSITE, &ip)) {
      Serial.println(F("Couldn't resolve!"));
    }
    delay(500);
  }
  cc3000.printIPdotsRev(ip);
  Serial.println("\n");
}

bool displayConnectionDetails(void)
{
  uint32_t ipAddress, netmask, gateway, dhcpserv, dnsserv;
  if (!cc3000.getIPAddress(&ipAddress, &netmask, &gateway, &dhcpserv, &dnsserv))
  {
    Serial.println(F("Unable to retrieve the IP Address!\r\n"));
    return false;
  }
  else
  {
    Serial.print(F("\nIP Addr: ")); cc3000.printIPdotsRev(ipAddress);
    Serial.print(F("\nNetmask: ")); cc3000.printIPdotsRev(netmask);
    Serial.print(F("\nGateway: ")); cc3000.printIPdotsRev(gateway);
    Serial.print(F("\nDHCPsrv: ")); cc3000.printIPdotsRev(dhcpserv);
    Serial.print(F("\nDNSserv: ")); cc3000.printIPdotsRev(dnsserv);
    Serial.println("\n");
    return true;
  }
}


void Get_Data(void)
{
  Adafruit_CC3000_Client www = cc3000.connectTCP(ip, 80);
  char _do = 0;
  Serial.println(F("---- Take Byte ...-------------------"));
  if (www.connected()) {
    www.fastrprint(F("GET "));
    www.fastrprint(WEBPAGE);
    www.fastrprint(F(" HTTP/1.1\r\n"));
    www.fastrprint(F("Host: ")); www.fastrprint(WEBSITE); www.fastrprint(F("\r\n"));
    www.fastrprint(F("\r\n"));
    www.println();
  } else {
    Serial.println(F("Connection failed"));
    return;
  }
  unsigned long lastRead = millis();
  int n = 0;
  while (www.connected() && (millis() - lastRead < IDLE_TIMEOUT_MS)) {
    while (www.available()) {
      char c = www.read();
      if (_do == 1 && n < DataOfPage * NumOfPage)
      {
        Data[n] = c;
        n++;
      }
      if (c == '#')
        _do = 1;
      lastRead = millis();
    }
  }
  if (n > 0)
    NumOfWord = (n + 1) / 32;
  Serial.print("Take Byte: "); Serial.println(n);
  Serial.println(F("-------------------------------------"));
  www.close();
}

 

LED_Array.h:

#ifndef LED_Array_H
#define LED_Array_H
#define     R0       2
#define     R1       3
#define     G0       8
#define     G1       9
#define     L0       11
#define     L1       12
#define     STB         A4//RCLK STCP
#define     CLK         A5//SCLK SHCP
#define     EN         13
#define     RowA        A0
#define     RowB        A1
#define     RowC        A2
#define     RowD        A3
void Write_595(unsigned char Data, unsigned char PIN_595);
//this is the base driver of 74HC595
void Init_LED_Array(void);
//put this function into setup()
void Display();
//you can modify this function to display contents that you what to show
void Write_LED_Array(unsigned long pos, unsigned char *pData, unsigned char COLOR);
//this is the base driver of LED array
#endif

 

LED_Array.cpp:

#include"LED_Array.h"
#include"Arduino.h"
void Display()//you can modify this function to display contents that you what to show
{
  unsigned char i;
  for (i = 80; i > 1; i--)
  {
    Write_LED_Array(0, &cod1[0x0000], R0); //Write_LED_Array(pos,data,color);
    Write_LED_Array(1, &cod1[64], R1);
  }
  for (i = 80; i > 1; i--)
  {
    Write_LED_Array(0, &cod1[128], R0); //Write_LED_Array(pos,data,color);
    Write_LED_Array(1, &cod1[192], R1);
  }

}
void Init_LED_Array(void)//put this function into setup()
{

  pinMode(R0, OUTPUT);
  pinMode(R1, OUTPUT);
  pinMode(G0, OUTPUT);
  pinMode(G1, OUTPUT);
  pinMode(L0, OUTPUT);
  pinMode(L1, OUTPUT);
  digitalWrite(R0, LOW);
  digitalWrite(R1, LOW);
  digitalWrite(G0, LOW);
  digitalWrite(G1, LOW);
  digitalWrite(L0, LOW);
  digitalWrite(L1, LOW);

  pinMode(STB, OUTPUT);
  pinMode(CLK, OUTPUT);
  pinMode(EN, OUTPUT);

  pinMode(RowA, OUTPUT);
  pinMode(RowB, OUTPUT);
  pinMode(RowC, OUTPUT);
  pinMode(RowD, OUTPUT);


  digitalWrite(EN, LOW);

}
void Write_595(unsigned char Data, unsigned char PIN_595) //this is the base driver of 74HC595
{
  digitalWrite(CLK, LOW);
  digitalWrite(PIN_595, (Data & 0x80));
  digitalWrite(CLK, HIGH);
  digitalWrite(CLK, LOW);
  digitalWrite(PIN_595, (Data & 0x40));
  digitalWrite(CLK, HIGH);
  digitalWrite(CLK, LOW);
  digitalWrite(PIN_595, (Data & 0x20));
  digitalWrite(CLK, HIGH);
  digitalWrite(CLK, LOW);
  digitalWrite(PIN_595, (Data & 0x10));
  digitalWrite(CLK, HIGH);
  digitalWrite(CLK, LOW);
  digitalWrite(PIN_595, (Data & 0x08));
  digitalWrite(CLK, HIGH);
  digitalWrite(CLK, LOW);
  digitalWrite(PIN_595, (Data & 0x04));
  digitalWrite(CLK, HIGH);
  digitalWrite(CLK, LOW);
  digitalWrite(PIN_595, (Data & 0x02));
  digitalWrite(CLK, HIGH);
  digitalWrite(CLK, LOW);
  digitalWrite(PIN_595, (Data & 0x01));
  digitalWrite(CLK, HIGH);
}
void Write_LED_Array(unsigned long pos, unsigned char *pData, unsigned char COLOR) //this is the base driver of LED array
{
#define LIGHT 160
  unsigned char *pTemp;
  unsigned char row;
  for (row = 0; row < 16; row++)
  {

    digitalWrite(EN, HIGH);

    pTemp = (pData + (row * 2));
    Write_595(*pTemp, COLOR);
    Write_595(*(pTemp + 1), COLOR);
    Write_595(*(pTemp += 32), COLOR);
    Write_595(*(pTemp + 1), COLOR);
    //        Write_595(*(pTemp += 32), COLOR);
    //        Write_595(*(pTemp + 1), COLOR);
    //        Write_595(*(pTemp += 32), COLOR);
    //        Write_595(*(pTemp + 1), COLOR);

    digitalWrite(STB, HIGH);
    delayMicroseconds(1);
    digitalWrite(STB, LOW);
    delayMicroseconds(1);

    digitalWrite(RowA, (row & 0x01)); //set display line
    digitalWrite(RowB, (row & 0x02)); //Sequential scan
    digitalWrite(RowC, (row & 0x04));
    digitalWrite(RowD, (row & 0x08));


    digitalWrite(EN, LOW);
    delayMicroseconds(LIGHT);

  }
#undef LIGHT
}

 




专家
2016-03-19 19:19:43     打赏
13楼
著名创客的帖子要顶

共13条 2/2 1 2 跳转至

回复

匿名不能发帖!请先 [ 登陆 注册 ]