Home / utk / cs130 / fa17 / lab05 / lab5stud.ino
Directory Listing
lab5stud.ino
writeup.pdf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
//Lab 5
//COSC 130

const int CLK_DIO = 7;
const int DATA_DIO = 8;
const int LATCH_DIO = 4;

//////////////////////////////////////////////
//
// Finish the arrays below
//
///////////////////////////////////////////////

//SEGMENTS contains the segment selector 0b1111XYZW
const int SEGMENTS[] = {0b11110001, /* finish here */};

//DIGITS contains the actual digits where DIGITS[0]
//will be the bit string to draw a 0 on the 7-segment display
const int DIGITS[] = {0b11000000, 0b11111001, /* finish here */};

///////////////////////////////////////////
//
// Modify SetupPins below
//
/////////////////////////////////////////////
void SetupPins()
{
  //Make sure that we can write to CLK_DIO, DATA_DIO, and LATCH_DIO

}

///////////////////////////////////////////
//
// Modify SetSegment below
//
/////////////////////////////////////////////
void SetSegment(int segment, int digit)
{
  //Set <segment>'s value to <digit>

  //DO NOT USE shiftOut() in this code!!!
  //Steps to write a value
  //1. Open the latch (LATCH_DIO) by setting it's value LOW using digitalWrite()
  //2. Write the first bit to DATA_DIO, cycle the clock (CLK_DIO) using digitalWrite()
  //3. ... Write the nth bit, cycle the clock using digitalWrite()
  //4. Close the latch (LATCH_DIO) by setting it's value HIGH using digitalWrite()
 
}



////////////////////////////////////////////
//
// Do NOT modify any functions below UNTIL STEP 3
//
////////////////////////////////////////////
const int segment_limit = sizeof(SEGMENTS) / sizeof(int);
const int digit_limit = sizeof(DIGITS) / sizeof(int);

int values[] = {0, 0, 0, 0};

void setup() {
  SetupPins();
  Serial.begin(115200);
  Serial.print("Enter value: ");
}

void loop() 
{
  if (Serial && Serial.available() > 0) {
    String input = Serial.readString();
    int value = input.toInt();
    char buf[10];

    if (value > 9999 || value < 0) {
      value = 1234;
    }
    values[0] = value / 1000;
    value -= values[0] * 1000;
    values[1] = value / 100;
    value -= values[1] * 100;
    values[2] = value / 10;
    value -= values[2] * 10;
    values[3] = value;
    
    sprintf(buf, "%d %d %d %d", values[0], values[1], values[2], values[3]);
 
    Serial.print("\nDisplay set to ");
    Serial.print(buf);
    Serial.print("\nEnter value: ");
  }
  for (int i = 0;i < 4;i++) {
    if (i >= segment_limit) {
      break;
    }
    if (values[i] < digit_limit) {
      SetSegment(i, values[i]);
    }
  }

}