Quiz Alarm

IA Kit Doc

Internal Memory

Appliance Control

Project

Quiz Alarm

// Fill in the place with /* */

/* include Incipe library*/

int count = 0; // count no. of correct ans
char ascii_time = 0;
int hour = 0;
int min = 0;
int min1 = 0;
int min2 = 0;
unsigned long previous_time = 0;
int interval = 5000; // 5s
int set_hour = 0;
int set_min = 0;
int randomNumber = 0;

#define SSID        "CSWNG"
#define PASSWORD    "ABC12345"
#define HOST_NAME   "www.baidu.com"
#define HOST_PORT   (80)

void setup(void)
{
  Serial.begin(9600);
  incipe.init();

  randomSeed(1111); // for generating random number

  if (incipe.wifi.joinAP(SSID, PASSWORD)) 
  {
    Serial.print("Join AP success\r\n");
    Serial.print("IP:");
    Serial.println( incipe.wifi.getLocalIP().c_str());       
  } 
  else 
  {
    Serial.print("Join AP failure\r\n");
  }
  incipe.wifi.disableMUX();
}

void loop(void)
{
  // set alarm time
  if (/* when a button is pressed */)
  {
    /* change set_hour depending on pressing + or - */
    /* print set_hour on screen */
  }
  /* repeat the process for min */

  //get actual time
  if (millis() - previous_time >= interval)
  {
    previous_time = millis();
    uint8_t buffer[1024] = {0};

    if (incipe.wifi.createTCP(HOST_NAME, HOST_PORT)) 
    {
      Serial.print("create tcp ok\r\n");
    } 
    else 
    {
      Serial.print("create tcp err\r\n");
    }

    char *hello = "GET / HTTP/1.1\r\nHost: www.baidu.com\r\nConnection: close\r\n\r\n";
    incipe.wifi.send((const uint8_t*)hello, strlen(hello));

    uint32_t len = incipe.wifi.recv(buffer, sizeof(buffer), 10000);
    if (len > 0) 
    {
      for(uint32_t i = 0; i < len; i++) 
      {
        if (i >= 123 && i <= 133)
        {
          /* (char)buffer[i] is the date, show it on screen */
        }
        if (i >= 135 && i <= 136)
        {
          // ascii_time = buffer[i];
          // if (ascii_time == 55){hour = 15;}
          // else if (ascii_time == 56){hour = 16;}
          // else if (ascii_time == 57){hour = 17;}
          /* print hour on screen */
        }
        if (i == 138)
        {
          min1 = buffer[i] - 48;
        }
        if (i == 139)
        {
          min2 = buffer[i] - 48;
        }
      }
      min = min1 * 10 + min2;
      /* print hour on screen */
    }

    incipe.wifi.releaseTCP();
  }

  //reach alarm time, ans Q
  if(set_hour == hour /* AND */ set_min == min)
  {
    randomNumber = random(3, 11); // generate random number from 3 to 10
    incipe.SwitchPage(randomNumber); // change pages
    while (/* correct number of ans smaller than 3 */)
    {
    incipe.PlaySound(); // start alarm
    delay(500);
    if (/* page value is 3 */)
    {
      if (/* button of correct ans is pressed */)
    {
      /* increase the count */
      randomNumber = random(3, 11); // generate random number from 3 to 10
    }
    }
    /* repeat for remaining pages (different questions) */
    incipe.screenWriteValue(/* name of your button */, -1);
    }
    incipe.SwitchPage(0);
  }
}

© 2025 INCIPE Academy Limited

Create a free website with Framer, the website builder loved by startups, designers and agencies.